fdupes – Find and delete duplicate files in Linux

Delete Duplicate Files From The Terminal Using Fdupes Command

We often have duplicate files stored in our directory, whether music, or documents. And deleting those files is very exhausting, specially when you don’t know which files have more than a one copy. That’s where fdupes command comes in. In this article, we will go through the installation process of this tool, and we will also learn how to use this.

What is fdupes?

Fdupes is a command line utility which identifies duplicate files by a number of methods one by one for you. First, it looks at the files and compares their size followed by a partial MD5 signature comparison and then a full MD5 signature comparison and at last, this performs a full byte-to-byte comparison between two files. This utility is written in C programming language by Adiran Lopez.

Installing fdupes on Linux distributions.

This application is available in the official repositories in every Linux distribution, so the Installation procedure becomes really easy. Just open a Terminal and then type the following commands, depending upon your Linux distribution :

# On Debian and Ubuntu-based distributions
sudo apt update && sudo apt install fdupes
# On Fedora Workstation
sudo dnf install fdupes
# On Arch Linux
sudo pacman -S fdupes
Installing Fdupes On Fedora
Installing Fdupes On Fedora

Usage of fdupes

I’m going to create several duplicate files for demonstration purposes of this tutorial, you can use it directly though.

mkdir ~/tutorial && cd ~/tutorial && for i in {1..10}; do echo "This is a sample file" > sample_file${i}.txt ; done
Creating Sample Files
Creating Sample Files

Now, let’s search for duplicate files using the fdupes command:

fdupes ~/tutorial
Lisitng Duplicate Files
Listing Duplicate Files

You can also search for duplicate files recursively within subdirectories using the -r flag. Using the -S option, you can also list out the size of all the files.

Displaying Size Of Files Using S Flag
Displaying Size Of Files Using -S Flag

Finally, to delete the duplicate files using this command, you can use the -d option. Be careful, always perform a double check so that you don’t lose your data. Enter the range of files to PRESERVE and then press enter to mark your selection.

Enter The Range Of Files To Delete
Enter The Range Of Files To Delete

After tagging the files, you can type prune and then press enter to delete all the unmarked (-) files.

Summary

This is a really lightweight, handy little tool that will save you a lot of time in the long run. You can look up more options of the fdupes command by typing the following command if you get confused about anything.

fdupes -h

References

Fdupes command – Gentoo Wiki