Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

when we use Expires header for text files like js, css, contents are cached in the browser, to get new content we need to change in the html file the new names in the link and script tag. When we add changes. How can we automate it.

I may have some bunch of html files in multiple folders also in subdirectories.

There would be a text file


OldName                 NewName
oldfile1-ver-1.0.js      oldfile1-ver-2.0.js  
oldfile2-ver-1.0.js      oldfile2-ver-2.0.js  
oldfile3-ver-1.0.js      oldfile3-ver-2.0.js  
oldfile4-ver-1.0.js      oldfile4-ver-2.0.js  

The script should change all the oldfile1-ver-1.0.js into oldfile1-ver-2.0.js in the html, php files

I would run this script before i start uploading.

Finally the script could create a list of files and line number where it made the update.

The solution can be in PERL/PHP/BATCH or anything thats nice and elegant

share|improve this question

2 Answers 2


find -type f -exec sed 's/ver-1.0/ver-2.0/g' -i {} \;


This would rename recursively on linux:

find -exec rename 's/ver-1.0/ver-2.0/' {} \;

On windows you can install cygwin and i think the syntax would be:

find -exec rename ver-1.0 ver-2.0 {} \;
share|improve this answer

What LatidSuD has handles the physical files themselves, but you probably want something like sed, or perl to handle the html references. Something like this should work:

perl -pi -e 's|ver-1\.0\.js|ver-2.0.js|g' *.html

This assumes you're only changing the version tag. If you're changing other parts, just correct the replace statement as necessary. To get fancy, you could include it as a bash script, and feed in the values, like this (named fix_references.sh for example):

perl -pi -e "s|$2|$3|g" $1

Then you simply call it like this:

./fix_references.sh filenametofix.php oldfile1-ver-1.0.js oldfile1-ver-2.0.js

Hope that gives you an idea.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.