Install fdupes on Ubuntu 20.04

One of the ways to free up disk space on the system is to delete the duplicate files. The fdupes is a tool that enables to find duplicate files and delete them via command line. Duplicate files are identified by comparing file sizes, MD5 signatures, and doing a byte-by-byte comparison.

This tutorial shows how to install fdupes on Ubuntu 20.04.

Install fdupes

Run the following command to update the package lists:

sudo apt update

Next, install fdupes:

sudo apt install -y fdupes

We can check fdupes version as follows:

fdupes --version

Testing fdupes

In order to test, create a text file and duplicate it:

echo "Hello" > test.txt
cp test.txt test2.txt
cp test.txt test3.txt

For example, to search duplicate files in the current working directory, run the following command:

fdupes .

When searching is finished, command prints duplicate files:

./test.txt
./test2.txt
./test3.txt

The -d option prompts user to specify the files which should be preserved, while deleting all others:

fdupes -d .

Duplicate files are listed and we need to choose which of them should be preserved:

[1] ./test.txt
[2] ./test2.txt
[3] ./test3.txt
 
Set 1 of 1, preserve files [1 - 3, all]:

In our case, we choose to preserve a first file. Other files will be deleted:

Set 1 of 1, preserve files [1 - 3, all]: 1
 
   [+] ./test.txt
   [-] ./test2.txt
   [-] ./test3.txt

The -r option can be used to find duplicate files recursively under every directory including subdirectories:

sudo fdupes -r /etc

It is possible to provide more than one directory:

sudo fdupes -r /etc /var/lib

Empty files can be ignored with -n option:

sudo fdupes -rn /etc /var/lib

Uninstall fdupes

If you wish to completely remove fdupes, run the following command:

sudo apt purge --autoremove -y fdupes

Leave a Comment

Your email address will not be published.