Jump to content

copying a single file to multiple locations


Guest delta_i
 Share

Recommended Posts

Guest delta_i

i have a large number of files named graphic_prefix_cat.gif, graphic_prefix_dog.gif, graphic_prefix_zebra.gif, etc... and i want them all to be replaced by a generic picture called graphic_prefix_animal.gif while retaining their original names. i know i can type:

cp graphic_prefix_animal.gif graphic_prefix_cat.gif

and replace them one at a time but rather than repeat this procedure dozens of times, is there a way to copy a single file over every file in a directory that begins with graphic_prefix_? this seemed like the kind of thing grep should be used for but i am pretty new to linux and couldn't figure out how to get there...

any help would be appreciated.

thanks.

Link to comment
Share on other sites

Welcome to the board! mub-beer.gif

 

Try this: (assuming the file you want to copy is called source.gif)

find . -name "graphic_prefix*" -exec cp source.gif \{\} \;

The find command finds all the files whose names begin with the given string, then the results are passed to the cp command which copies source.gif into each of the passed files. (I avoided calling the source file graphic_prefix_animal.gif because then that file would be found by the find command too)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...