Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 02-10-2005, 07:17 PM   #1
Registered: Sep 2004
Posts: 63

Rep: Reputation: 15
Copy files from different directories

The normal
 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:
 cpx  ~/*.py  collecting_dir
What is the bash command (if any)?
Old 02-10-2005, 07:25 PM   #2
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, 07:52 PM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
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, 04:01 AM   #4
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.


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

All times are GMT -5. The time now is 09:08 AM.

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