[Techtalk] copying similar files in one command

Magni Onsoien magnio+lc-techtalk at pvv.ntnu.no
Mon Nov 1 02:55:35 EST 2004


On 2004-10-31 05:21:38 -0600, percila orphan said:
> I need help with the cp command.
> Sometimes I'm have to copy a lot of files that
> have something in thier names in common.
> For example, if they all have the word "ed" in them.
> /home/ed/ ls -l | grep "ed"  displays all the files with the word
> "ed" in them within that directory /home/ed/
> I want to copy those files to the directory  /usr/temp
> Can I copy them all with one command? What might
> that be?  

You may use wildchars and let your shell take care of finding the files
for you (this is called file expansion):

cp *ed* /home/newdir

will copy all files with *ed* in them; if you also want the directories
copied, you'll have to use 'cp -r' in stead. And you can also use this
for other commands, like mv (move) or scp (remote copy via ssh).

Hope this helps.



Magni :)
-- 
sash is very good for you.


More information about the Techtalk mailing list