I want to delete same file with different names scattered in folders. This command works fine for searching and listing the files. Then I manually delete the files.

Is it possible to add delete option to the below command ?

find /folder -type f -exec md5sum {} + | grep '^aafa26a6610d357d8e42f44bc7e76635'
  • 3
    If you know the size of the file, you would be able to potentially speed it up considerably by only computing the checksums of the files with the exact same size (-size 12345c -exec md5sum {} + for a file size of 12345 bytes for instance) – Stéphane Chazelas Sep 6 '17 at 12:48


find ... | awk '{$1 = "rm" ; print } ' | bash

this will replace actual md5sum (aaf...) by rm.

this will not work if filename have a special character in it, neither if file is write protected (replace rm by rm -f ).


Another possibility is below. Replace rm with rm -f if required. Also, add -n1 to xargs (removing the rm) to have it print the arguments passed to it (for validation purposes).

find . -type f -exec md5sum {} + | awk '$1 == "d41d8cd98f00b204e9800998ecf8427e" {printf "%s\0", substr($0, 35)}' | xargs -r0 rm

Note this method does handle spaces in filenames and/or folders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.