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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...