LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-25-2020, 01:26 PM   #1
the_penguinator
Member
 
Registered: Jan 2009
Location: Canada
Distribution: slackware, OpenBSD, OSX
Posts: 233

Rep: Reputation: 25
Beginner cp help needed (don't hate me for forgetting)


I've got /home/b***/recovered-from-mbp/ with a 1000 directories i.e., /recup_dir.1-->1014 underneath that. I want to use cp to copy only *.NEF, *.jpg etc. from those 1000 directories to /recovered-images. For example, if I go to the top of that tree this

$ find -iname '*.nef' -exec cp {} /home/b***/recovered-images/ \;

means I have to go into each of the 1000 directories individually and I'm trying to avoid that---despite having lots of time on my hands currently... Clues happily read!
 
Old 03-25-2020, 02:07 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,258
Blog Entries: 3

Rep: Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713
If you want to copy them all to the same destination directory, that is easy. Fix the syntax you have for the find utility. See "man find"

Code:
find /home/b***/recovered-images/ -iname '*.nef' -exec echo cp -p {} /some/destination/ \;
If you need a more complex decision made about where to copy the files to, then please provide a little more detail and maybe some examples.
 
2 members found this post helpful.
Old 03-25-2020, 02:38 PM   #3
karlmag
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 127

Rep: Reputation: Disabled
If you are copying files from a huge directory tree into *one* directory - are you *sure* you don't have any filename overlap somewhere? If there is you *will* end up with only the last version of file with that particular name in your destination dir.

--
KarlMag
 
1 members found this post helpful.
Old 03-25-2020, 02:40 PM   #4
drgibbon
Senior Member
 
Registered: Nov 2014
Distribution: Slackware64 15.0
Posts: 1,212

Rep: Reputation: 936Reputation: 936Reputation: 936Reputation: 936Reputation: 936Reputation: 936Reputation: 936Reputation: 936
The find man page recommends:
Code:
-exec command '{}' \;
Quote:
Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation.
 
1 members found this post helpful.
Old 03-25-2020, 02:53 PM   #5
the_penguinator
Member
 
Registered: Jan 2009
Location: Canada
Distribution: slackware, OpenBSD, OSX
Posts: 233

Original Poster
Rep: Reputation: 25
[QUOTE=Turbocapitalist;6104304]If you want to copy them all to the same destination directory, that is easy. Fix the syntax you have for the find utility. See "man find"

Thanks kindly, specified dirs and removed the echo and all went as it should have. I haven't had to do this kind of a cleanup for a few years. Much obliged!
 
Old 03-25-2020, 02:55 PM   #6
drgibbon
Senior Member
 
Registered: Nov 2014
Distribution: Slackware64 15.0
Posts: 1,212

Rep: Reputation: 936Reputation: 936Reputation: 936Reputation: 936Reputation: 936Reputation: 936Reputation: 936Reputation: 936
Quote:
Originally Posted by karlmag View Post
If you are copying files from a huge directory tree into *one* directory - are you *sure* you don't have any filename overlap somewhere? If there is you *will* end up with only the last version of file with that particular name in your destination dir.
The -n/--n-clobber flag on cp would be a good idea then.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: I hate Unity. I hate GNOME. I hate Windows 8. The ultimate desktop search continues. LXer Syndicated Linux News 1 11-09-2011 07:20 PM
KDE Forgetting file assocations, Previous solutions I found don't work JediToren Mandriva 1 01-23-2005 09:07 AM
RH9 lvm and fdisk forgetting about hdb partitions davel75 Linux - Software 0 10-27-2003 09:59 AM
'Open With...' forgetting Micro420 Mandriva 1 10-03-2003 10:55 AM
Why does Xconfigurator keep forgetting my XConfig? Bert Linux - Software 2 09-11-2002 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration