Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would to write a bash script to find duplicate files but I don't want just use md5sum. It means, in addition to use md5sum I want to check my files with cmp command.

I use the command below for finding duplicate files. Right now I need to write a loop and use cmp command for finding duplicates. How can I write a loop and write a bash script?

find . -type f | xargs -I%  md5sum % | sort | uniq -w32 -D| cut  -f3 -d' '
share|improve this question

migrated from Oct 5 '11 at 22:11

This question came from our site for professional and enthusiast programmers.

what is leading you to do cmp in addition of md5sum ? Are you afraid of hash collision ? – Cédric Julien Oct 5 '11 at 12:43
No this is my assignment and i have to write a bash script and find duplicate file – Elham abbasi Oct 5 '11 at 12:45
Question also exists on unix&linux SE – glenn jackman Oct 5 '11 at 13:41

Give this short introduction to Bash a look.

If you wrote the one-liner in your question, the first part will be quite boring for you, but you can just skip to the Control structures section. The basic tools for flow control (if/for/while/do...while) are described there, with nice examples.

share|improve this answer
thank you, it is useful for me – Elham abbasi Oct 5 '11 at 13:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.