[Techtalk] copying similar files in one command

Akkana Peck akkana at shallowsky.com
Mon Nov 1 04:39:45 EST 2004


percila orphan writes:
> /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?  

In addition to the solutions already given, or if you want to look
deeper in a directory hierarchy rather than at just one level, "find"
can do it in one (arcane) command:

find /home/ed -name "*ed*" -exec cp "{}" /usr/tmp \;

"{}" means "put the file's name here", so this just looks for
any file matching the pattern "*ed*", then runs cp to copy that
file to /usr/tmp.

You might not need the quotes around {} in bash; you do in csh.

	...Akkana


More information about the Techtalk mailing list