Recursively change filenames and find/replace text in Linux

You can use the "rename" command to do pattern-matched renaming of files, but it can also work with the find command.

The problem is if the directory names change as well as the files. Therefore a good technique is to rename the folders first, then the files.

find . -type d|xargs -r rename "s/Old/New/g"
find . -type f|xargs -r rename "s/Old/New/g"

You can use "sed -i" to interactively find/replace text in files. Combine that with find and you can do it recursively.

find . -type f -exec sed -i 's/Startnet2019/Startnet2019/g' {} \; -print

If you are developing you probably want to ignore the ".git" folder as well.

find . -path ./.git -prune -o -type f -exec sed -i 's/Startnet2019/Startnet2019/g' {} \; -print

Leave a Reply