Move all images in folder to subfolder, and update all references to those images to their new location?

Posted by Professor Frink on Server Fault See other posts from Server Fault or by Professor Frink
Published on 2011-03-04T15:10:35Z Indexed on 2011/03/04 15:26 UTC
Read the original article Hit count: 270

Filed under:
|
|
|
|

I have a folder which contains a ~50 text files (PHP) and hundreds of images. I would like to move all the images to a subfolder, and update the PHP files so any reference to those images point to the new subfolder.

I know I can move all the images quite easily (mv *.jpg /image, mv *.gif /image, etc...), but don't know how to go about updating all the text files - I assume a Regex has to be created to match all the images in a file, and then somehow the new directory has to be appended to the image file name? Is this best done with a shell script? Any help is appreciated (Server is Linux/CentOs5)

Thanks!

© Server Fault or respective owner

Related posts about linux

Related posts about bash