Install fdupes on Ubuntu 24.04

Install fdupes on Ubuntu 24.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 24.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

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 the 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:

Set 1 of 1:

  1 [ ] ./test.txt
  2 [ ] ./test2.txt
  3 [ ] ./test3.txt
 
( Preserve files [1 - 3, all, help] ):
Type 'exit' to exit fdupes.

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

Set 1 of 1:

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

( Preserve files [1 - 3, all, help] )= 1
1 files marked for preservation, 2 for deletion

Once files selected for deletion, type prune command. To exit prompt, enter exit command.

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

Cancel reply

Your email address will not be published.