LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-10-2005, 06:17 PM   #1
fiomba
Member
 
Registered: Sep 2004
Posts: 63

Rep: Reputation: 15
Copy files from different directories


The normal
Code:
 cp -r Starting_dir  Ending_dir
replicates in the ending dir the directory tree of starting dir.

Instead, I want to copy (for example) all the python files (ending with *.py), scattered all over my home (in different subdirs) into a unique directory, by means of a command like this:
Code:
 cpx  ~/*.py  collecting_dir
What is the bash command (if any)?
 
Old 02-10-2005, 06:25 PM   #2
secesh
Senior Member
 
Registered: Sep 2004
Location: Savannah, GA
Distribution: Ubuntu, Gentoo, Mythbuntu, ClarkConnect
Posts: 1,154

Rep: Reputation: 47
cp ~/*.py /some/destination/

you can still use -R for recursive...
 
Old 02-10-2005, 06:52 PM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
You could try
find ~ -name "*.py" -exec cp "{}" <destination-dir>/ \;

In a script, the variable $HOME is usually used instead of '~'.

As I understand your question, you want all of the scripts copied into the same target directory, without any of the subdirectories copied as well.
 
Old 02-11-2005, 03:01 AM   #4
fiomba
Member
 
Registered: Sep 2004
Posts: 63

Original Poster
Rep: Reputation: 15
Hi ,
thank for your replies.
jschiwal is correct . I have found the same indications (after posting ... RTM !) in the O'Reilly's "Unix Power Tools" about the use of find + -exec command (pag. 291 of the 2nd Edition).
About the secesh's reply, I think that he wanted correct my "cpx"...
I only used cpx has a placeholder of something else:
the command with cp does not work as I am looking for.
 
  


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
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 07:56 PM
Copy one file to multiple directories cmfarley19 Linux - General 9 11-10-2004 12:57 PM
How do I copy home directories back? G-wizz Linux - Newbie 5 06-11-2004 06:20 AM
find and copy files into multiple directories avargas22 Linux - Newbie 2 04-01-2004 11:11 AM
copy directories and subdirectories Red Squirrel Linux - Newbie 2 03-06-2004 09:18 PM


All times are GMT -5. The time now is 03:08 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration