Noob questions

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
walrus_t
Level 2
Level 2
Posts: 62
Joined: Thu Aug 04, 2011 2:41 am

Noob questions

Post 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...

mintybits
Level 6
Level 6
Posts: 1123
Joined: Fri Jan 27, 2012 5:09 pm

Re: Noob questions

Post 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/

walrus_t
Level 2
Level 2
Posts: 62
Joined: Thu Aug 04, 2011 2:41 am

Re: Noob questions

Post by walrus_t »

Thanks! That worked perfectly! I would never have found that by myself :)
Any solution using only cp command? Just for "fun" :)

mintybits
Level 6
Level 6
Posts: 1123
Joined: Fri Jan 27, 2012 5:09 pm

Re: Noob questions

Post 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:

rhodry
Level 4
Level 4
Posts: 343
Joined: Mon Jun 04, 2007 7:32 am

Re: Noob questions

Post 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.
Life isn't about waiting for the storm to pass...
it's about learning to dance in the rain.

walrus_t
Level 2
Level 2
Posts: 62
Joined: Thu Aug 04, 2011 2:41 am

Re: Noob questions

Post 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!

User avatar
ingeva
Level 3
Level 3
Posts: 176
Joined: Wed Jun 20, 2012 3:39 am
Location: Sandvika, Norway

Re: Noob questions

Post 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.
Mint rules!

Post Reply

Return to “Newbie Questions”