Page 1 of 1

Noob questions

Posted: Tue Jul 10, 2012 2:42 pm
by walrus_t
Hi,
Sorry to ask but I can't find an answer using man pages. I have a folder (let's name it "Main") containing many subfolders. Each of these subfolders contains many files, some of them are PDFs. I want to copy the "Main" folder with all its subfolders but only PDFs in them, not the other files that are currently in these subfolders.
I tried to read man pages but can't find any answer. Any help please?
Thanks!
Sorry, bad english but not my native language...

Re: Noob questions

Posted: Tue Jul 10, 2012 2:52 pm
by mintybits
Try this:
Let's say you are in the directory containing "Main" and you want all the copied directories and PDF files put in a directory called "temp".

Code: Select all

find Main/ | grep .pdf | rsync -va --files-from=- . temp/

Re: Noob questions

Posted: Tue Jul 10, 2012 3:01 pm
by walrus_t
Thanks! That worked perfectly! I would never have found that by myself :)
Any solution using only cp command? Just for "fun" :)

Re: Noob questions

Posted: Tue Jul 10, 2012 3:08 pm
by mintybits
walrus_t wrote:Thanks! That worked perfectly! I would never have found that by myself :)
Any solution using only cp command? Just for "fun" :)
This is your idea of fun? :P
I use rsync for copying everything nowadays; once you've gained your PhD in the man page it is blissful. You'll have to read the cp man page if you insist. :wink:

Re: Noob questions

Posted: Wed Jul 11, 2012 12:52 am
by rhodry
Just FYI,
cp does have a -r option for recursive copy, but, I agree with @mintybits that rsync is a much better (more powerful, more flexible) option for all copying other than the most simple stuff. You could have used "include" & "exclude" statements on rsync as an alternative (see man rsync). Also, if you prefer a gui for this sort of thing, install Grsync - it is a really easy to use front end for the rsync command.

cheers,
rhodry.

Re: Noob questions

Posted: Wed Jul 11, 2012 1:10 am
by walrus_t
Yes, I tried that -r option but without success. I guess I should learn to use rsync properly as it seems to be really powerful!
Thanks again for your advice!

Re: Noob questions

Posted: Sun Jul 15, 2012 5:41 am
by ingeva
walrus_t wrote:Yes, I tried that -r option but without success. I guess I should learn to use rsync properly as it seems to be really powerful!
Thanks again for your advice!
I use rsync a lot, and it's a great program, but cp can be simpler.
I would use this command:

cp -av Main/*.pdf destination

As simple as that. The 'a' is the archive option (traverses directories), 'v' is for visual output if you want that.
You can also use the 'u' (update) option to copy only newer files.