I want to replace all files in a target path with the same name as original.file AND the same hash as orignal.file with new.file. What's the command to do this?Say I have updated the contents of a file, and now I want all other copies of that file in a certain path to be updated as well.In most cases the following code would work:find /target_path/ -iname original.file -exec cp new.file '{}' However if original.file is readme.txt for example, many unrelated files would be overwritten.
Replace all files with identical hash
linux;bash;hashsum
This this will require a test to see if the checksums match before decide to run the cp, you will have to run a subshell as the -exec argument to find. This should do the job:find /target_path/ -iname original.file -exec bash -c \  '[[ $(md5sum original.file) = $(md5sum {}) ]] && cp new.file {}' \;