How do I find and delete duplicate files in Linux?

Are you sick of duplicate files taking all your disk space and cluttering up your work? well, don’t worry, in this post we present you quick and easy ways to find and delete duplicate files in Linux.

There are several ways to find and delete duplicate files in Linux. Here are a few options:

1. Use the fdupes command:

The fdupes command is a utility that can identify and delete duplicate files. To use it, navigate to the directory you want to search for duplicates, and run the following command:

fdupes -rd .

The -r flag tells fdupes to search recursively through the directory and its subdirectories, and the -d flag tells it to delete the duplicate files. The . at the end specifies the current directory.

2. Use the find command:

You can use the find command to search for duplicate files based on their size and content. Here’s an example command that will find all files with the same size in the current directory:

find . -type f -printf "%s\n" | sort | uniq -d | xargs -I{} -n1 find . -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate | sed -n 's/^\(.*\)[[:space:]]\1$/\1/p' | xargs -I{} rm {}

This command will delete all the duplicates that it finds. If you just want to list the duplicates without deleting them, you can remove the xargs -I{} rm {} at the end.

3. Use a graphical tool:

There are also several graphical tools that you can use to find and delete duplicate files in Linux. One example is Duplicate File Finder, a free and open-source tool that allows you to scan your directories for duplicates and delete them. To use it, install the tool and run it from the command line:

sudo apt-get install duplicate-file-finder duplicate-file-finder

This will open the Duplicate File Finder window, where you can select the directories you want to scan and choose which duplicates you want to delete.

Summary
How do I find and delete duplicate files in Linux?
Article Name
How do I find and delete duplicate files in Linux?
Description
In this post, we'll show you how to find and delete duplicate files in Linux using a variety of tools and techniques. From the command line to graphical utilities, we've got you covered.
Author

Leave a Comment