Guest delta_i Posted January 13, 2007 Report Share Posted January 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
neddie Posted January 13, 2007 Report Share Posted January 13, 2007 Welcome to the board! 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) Quote Link to comment Share on other sites More sharing options...
Guest delta_i Posted January 13, 2007 Report Share Posted January 13, 2007 thank you, neddie. that worked perfectly. Quote Link to comment Share on other sites More sharing options...
neddie Posted January 14, 2007 Report Share Posted January 14, 2007 Cool! B) You're welcome! Quote Link to comment Share on other sites More sharing options...
emmanuel_uk Posted January 15, 2007 Report Share Posted January 15, 2007 a variation on -exec is to use | xargs Saying that not sure it would work with this case Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.