Saturday, April 16, 2011

Replacing a path in all files in a directory tree

Sometimes it is necessary to change a hardcoded path in all files in a given directory tree (i.e. if you migrated to a new home folder and need to change the paths to your libraries in all of your scripts).

This can be achieved extremely easily with some bash magic:

find . -type f | grep $PATTERN | xargs perl -pi -e "s|$OLD_PATH|$NEW_PATH|"

No comments:

Post a Comment