LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Copy files from different directories (https://www.linuxquestions.org/questions/linux-software-2/copy-files-from-different-directories-288678/)

fiomba 02-10-2005 06:17 PM

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)?

secesh 02-10-2005 06:25 PM

cp ~/*.py /some/destination/

you can still use -R for recursive...

jschiwal 02-10-2005 06:52 PM

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.

fiomba 02-11-2005 03:01 AM

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.


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