LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-16-2005, 08:16 AM   #1
Whiskerz
LQ Newbie
 
Registered: Dec 2005
Posts: 17

Rep: Reputation: 0
Recursive Copy of certain files


Hi all,

just started out with Linux so I'm unsure if this question goes here but anyway : I have lots of files distributed in a directory tree (in this case having a .java ending) I would like to extract from that tree and put them all into the same destination directory (lets call it "source"). I tried that with copy -R but noticed it would copy all files, and trying copy -R *.java would not find a single file (probably because the pattern does not match any subdirectory names?). I tried using find but failed in getting the files I found to copy to that one destination directory.

Any ideas?

Whizz
 
Old 12-16-2005, 08:29 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Greeeetings!

Try this
Code:
find /some/directory -type f -name '*.java' -exec cp {} /new/directory \;
 
Old 12-16-2005, 08:38 AM   #3
Whiskerz
LQ Newbie
 
Registered: Dec 2005
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks! Works fine! Now however in order to actually learn what I've been doing :

What does {} do? Is this a symbol for the list of files created by find? Does it belong to find (sort of like a variable find will then put each found match in) or is it part of the cp syntax?

What do i need \; for? First time I encounter this combination in a command, is it needed to specify the end of the -exec option? Would just \ or just ; be sufficient? Or do they symbolize different endings (e.g. \ is the end of the first command to execute, and you can give another command after it, and ; is the end of all execute commands)?

Would be great if you could enlighten me there ^.^

Whizz
 
Old 12-16-2005, 08:56 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Might be best if you run the command:man find and have a look under these sections.
ACTIONS
EXAMPLES
 
Old 12-16-2005, 09:24 AM   #5
Whiskerz
LQ Newbie
 
Registered: Dec 2005
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks again! That did clear up things, though like all man pages its also quite confusing for someone not knowing the exact workings of a shell . Will be reading up on that a bit I guess ^.^

/Whizz
 
Old 12-18-2005, 07:06 PM   #6
jamie_barrow
Member
 
Registered: Jul 2003
Location: Gauteng, South Africa
Distribution: Windows XP, yup :D Will be back onto Ubuntu probably someday
Posts: 107

Rep: Reputation: 15
\ is used to escape a character, since ; is a special character in the shell (to seperate consecutive commands) it needs to be escaped as \;.

Similarly, if you have a folder named "This is a folder", to cd into the folder, the spaces must be escaped,

cd This\ is\ a\ folder

I dont know what the {} does either though. Maybe its in the man? Can't be bothered to look yet
 
  


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
Recursive Copy fizgig10 Linux - Newbie 1 07-16-2005 11:58 PM
chmod recursive on files on dlublink Linux - Newbie 6 03-02-2005 08:45 AM
rox + recursive permission change for FILES only? NonSumPisces Linux - Newbie 9 08-11-2004 07:21 PM
How to do recursive file copy of directory for specific files? Arodef Linux - Newbie 4 06-29-2004 05:35 PM
recursive checking and log files (tripwire) wedgeworth Linux - Security 2 05-28-2004 12:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:14 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration