Install fdupes on Raspberry Pi

Install fdupes on Raspberry Pi

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

This tutorial demonstrates how to install fdupes on Raspberry Pi.

Connect to Raspberry Pi via SSH. Then run the following commands to update the package lists and install fdupes:

sudo apt update
sudo apt install -y fdupes

We can check the fdupes version with command:

fdupes --version

For testing purpose, we create a text file and then duplicate it.

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

Now run the fdupes command and specify directory where you want to find duplicate files. For example, the following command searches duplicate files in the current working directory:

fdupes .

When searching is completed, command prints duplicate files:

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

We can use -d option that prompts user to specify the files which should be preserved, while deleting all others.

fdupes -d .

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

[1] ./test.txt
[2] ./test2.txt
[3] ./test3.txt

Set 1 of 1, preserve files [1 - 3, all]:

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

Use -r option to search duplicate files recursively under every directory including subdirectories:

sudo fdupes -r /etc

We can also specify more than one directory:

sudo fdupes -r /etc /var/lib

To ignore empty files, use -n option:

sudo fdupes -rn /etc /var/lib

If you want to completely remove fdupes, execute the following command:

sudo apt purge --autoremove -y fdupes

Leave a Comment

Cancel reply

Your email address will not be published.