Find and Replace in Multiple Files in a Directory Tree Skipping Binary Files (Text files Only)

Written by James McDonald

July 9, 2013


cd /top/of/tree/to/change

fgrep -IlR server_name_here \| 
grep -v "log" \|
xargs sed -i.bak -e 's/server_name_here/new_server_name_here/g'

Find all non binary files (-I) and list them (-l) in the current and sub-directories

Skip any file that has “log” in the name or in the path

Then using sed make a backup copy with a .bak extension and globally find “server_name_here” and replace with “new_server_name_here”


Submit a Comment

Your email address will not be published.

You May Also Like…


Zebra Printer Language The above website has a page where you can enter ZPL and it...