[Techtalk] copying similar files in one command

Terri Oda terri at zone12.com
Mon Nov 1 02:48:05 EST 2004


On Oct 31, 2004, at 6:21 AM, percila orphan 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?

It's not *exactly* one command, but assuming you're in the bash shell, 
I'd use a loop as follows:

for file in /home/ed/*ed*; do cp $file /usr/temp; done

(You can do loops in any shell, as far as I know, but bash is the only 
one whose syntax I remember off the top of my head.)



More information about the Techtalk mailing list