Categories: LinuxUbuntu

How to Find and Delete Duplicate Files in Ubuntu Using Fdupes

It's quite common to end up with many copies of the same file on your computer while working with huge volumes of media and documents.

Eventually, you'll end up with a mess of files and an additional storage shortage due to duplicate files, prompting you to run a duplicate file check on your system.

Checking for duplicate files manually is not an option for obvious reasons. You can use various programs to discover and delete duplicate files to accomplish this.

In this article, you will learn to manage your duplicate files with fdupes, which is a Linux software that not only detects duplicates but also gives you multiple options to deal with them.

Prerequisites

  • A Linux-based system
  • Terminal access
  • A user account with sudo privileges.

Note: The commands in this tutorial are executed on the Ubuntu 22.04 system. All the instructions in the tutorial are valid for any Linux-based system.

Install Fdupes in Ubuntu

The fdupes installation package comes with all major Linux distributions. To install fdupes in Ubuntu, run the following apt command.

sudo apt install fdupes
sudo apt install fdupes

Find Duplicate Files With Fdupes

Once the installation is finished, you can use fdupes to identify duplicate files. To find duplicate files, run the following command with your directory path.

fdupes <directory path>

You can see the duplicate files presented in the output.

Search for Duplicate Files in Subfolders With Fdupes

The above command only finds duplicate files within the current folder. It does not look through the subfolders and such. To find duplicates throughout the folder and subfolders, you need to run the fdupes command with the -r option.

fdupes -r <directory path>

You can see from the output that the "-r" option does a more thorough search for duplicates in the folders and subfolders.

Search for Non-Empty Duplicate Files With Fdupes

You can also search for non-empty duplicate files. This will help you focus on the task, and you will not have to deal with empty files. To use this option, use the following command.

fdupes -n <directory path>

Get Information About Duplicate Files With Fdupes

Run the fdupes command with the -m option to get more information on the set of duplicate files.

fdupes -m <directory path>

You can also run the fdupes command with the -S option to get size information about the duplicate files.

fdupes -S <directory path>

Run the following command to save the fdupes command’s outputs.

fdupes <directory path> > output.txt

Delete Duplicate Files With Fdupes

Once you have narrowed down the duplicates in the directory, you can delete the duplicates by running the fdupes command with the -d option.

fdupes -d <directory path>

You will be prompted to preserve versions out of the duplicate files list. Simply enter the file number mentioned in the list to preserve the file.

Advanced Options in Fdupes Command

You can run the fdupes commands with multiple options to avail of the offered benefits. Such as, you can find all the non-empty files in the folders and subfolders with the following command.

fdupes -n -r <directory path>

Or get overall information about all the duplicate files within the folders and subfolders.

fdupes -m -r <directory path>

Conclusion

File organization is a time-consuming process in and of itself. When you factor in the time and work it takes to organize your disorganized storage, you look at a few hours of wasted time and effort.

However, owing to applications like fdupes, identifying duplicate files and deleting them has never been easier or more efficient. The instructions in this article will provide you with multiple options on how to treat your duplicate files.

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago