[Techtalk] copying similar files in one command

Wim De Smet kromagg at gmail.com
Mon Nov 1 22:05:39 EST 2004


On Sun, 31 Oct 2004 05:21:38 -0600, percila orphan
<millward at ms.umanitoba.ca> wrote:
> 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?
> As it is now, I'd have to spend 10 or more minutes typeing
> away like a fiend to get it done. Any suggestions would
> be welcome!

Along with all the other suggestions, if you ever find yourself
wanting to pipe something to a command that takes it's arguments as,
well, arguments, then use xargs.

like: ls <dir> | xargs rm (not a very usefull example, but this will
delete all files in the current dir)

xargs will also work around any limitations on the number of arguments
you pass to a command. Can be handy when working with a couple of K of
files.

greets,
Wim


More information about the Techtalk mailing list