Guest delta_i Posted January 13, 2007 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. Link to comment Share on other sites More sharing options...
neddie Posted January 13, 2007 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) Link to comment Share on other sites More sharing options...
Guest delta_i Posted January 13, 2007 Share Posted January 13, 2007 thank you, neddie. that worked perfectly. Link to comment Share on other sites More sharing options...
neddie Posted January 14, 2007 Share Posted January 14, 2007 Cool! B) You're welcome! Link to comment Share on other sites More sharing options...
emmanuel_uk Posted January 15, 2007 Share Posted January 15, 2007 a variation on -exec is to use | xargs Saying that not sure it would work with this case Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now