Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have thousands of web files(*.php, *.htm, *.html, etc) that contain an absolute path( I need to scan a directory and all subdirectories for the various file types and within those files, modify my absolute path to a relative one of my choosing and then leave the rest of the file as is. It must not change the path of any other absolute URLs though.

I've checked the similar questions already posted on the matter but none seem to address this directly. Any suggestions? Thanks!

share|improve this question
up vote 4 down vote accepted
find . -type f -print | 
  xargs sed -i.bak 's# else#g'
share|improve this answer
I think that will do it. There is a test flag for sed, right? – Publiccert Feb 27 '12 at 18:00
Since -i.bak will create the backups in their current web accessible location, could I suggest that you move them after the operation is complete? You probably want to avoid an potential for exposing your server side bits as plain text. – Aaron Copley Feb 27 '12 at 18:32
@AaronCopley That's a good point. Luckily, this is just the data migration. None of the externally routable IPs are pointing to this site yet. – Publiccert Feb 27 '12 at 18:51

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.