Find duplicate files

Sep 10, 2012·
Julio Batista Silva
Julio Batista Silva
· 2 min read
blog

Duplicate files take up disk space for no reason. Fortunately there are tools that automate the search for duplicates.

Fdupes

Install fdupes:

julio@acer ~> sudo pacman -S fdupes

Run fdupes in recursive mode (-r) and send the output to a file:

julio@acer ~/Documentos/Ebooks> fdupes -r . > dupes1.txt

On my computer this command took only 7 minutes to analyze 23500 files. The output file, dupes1.txt, had 5714 lines!

julio@acer ~/Documentos/Ebooks> fdupes -rf . > dupes2.txt

It took about 7 minutes to analyze 23500 files: dupes2.txt: 3878 lines

After removing the blank lines from dupes2.txt with sed -i '/^$/d' dupes2.txt, the file was down to 2054 lines.

Many of the files it flagged as duplicates were identical on purpose. Examples in programming books are often repeated. Some version control files (git, svn, and so on) were flagged as duplicates, but they should not be deleted.

If you want to cut down on disk usage while avoiding breaking anything, you can write a script that replaces every duplicate file with a hard link.

Delete every duplicate file (be careful with this script):

julio@acer ~/Documentos/Ebooks> while read f; do rm "$f"; done < dupes2.txt

Gemini

A good paid alternative for the Mac is Gemini, which lists all the duplicates in a friendly interface and lets you preview them before sending them to the trash.

Julio Batista Silva
Authors
Senior Cloud Developer

I’m a Brazilian-German computer engineer based in Germany, passionate about tech, science, photography, and languages.

I’ve been programming for about two decades already, exploring everything from mobile apps and web development to machine learning. These days I focus on cloud SRE and data engineering.

I volunteer in the open source and Python communities, helping organize PyCon DE and PyData Berlin, serving on the PSF D&I Work Group, mentoring, and contributing code and translations.

On my blog, I share Linux tips, setup guides, and personal notes I’ve written for future reference. I hope others find them helpful as well. The content is available in multiple languages.

Browse my gallery for some of my photography.

Away from the keyboard, you’ll find me at concerts, playing clarinet, cycling, scuba diving, or exploring new places, cultures, and cuisines.

Always happy to connect! 🙂

comments powered by Disqus