I am using the following commandfind . -type f -exec sed -i 's/_backpack.html/_backpack_cal.html/g' {} +I expect all _backpack.html strings in my project to be replaced to _backpack_cal.html and this happens.However, the problem is that it also edits my .git directory which corrupts git.How can I prevent find from touching my .git directory at the same time working with all the other sub-directories
How can I replace string in all files in a directory and all sub-directories without changing any of the hidden directories/files?
find
You could use :find . -name .git -prune -o -type f -exec sed -i 's/_backpack.html/_backpack_cal.html/g' {} +I added the -name .git -prune section which basically means if the name of the directory is .git, do not process that directory.Also, please note the added -o (meaning or) which only executes your statement if the first one is false (ie if the name of the processed file is the .git directory).Of course, you should test this before actually executing the command, by replacing the -exec ... part with a -print, for example.