6 Powerful Linux Commands to Find and Remove Duplicate Files
This guide explains six practical Linux commands—diff, cksum, find, fslint, rdfind, and fdupes—that help you locate identical files across Windows or Linux systems and safely delete them to reclaim valuable disk space.
Both Windows and Linux computers accumulate duplicate files over time, which waste disk space and slow down the system. The following six methods show how to quickly identify and remove those duplicates.
1. Use diff command
The diff command compares two files and displays differences with < and > symbols; if there is no output, the files are identical.
<code>$ diff index.html backup.html
2438a2439,2441
> <pre>
> That's all there is to report.
>When the files are the same:
$ diff home.html index.htmlNote that diff can only compare two files at a time, making it inefficient for large sets.
2. Use checksum ( cksum )
cksumcomputes a numeric checksum for each file; identical files share the same checksum.
$ cksum *.html
2819078353 228029 backup.html
4073570409 227985 home.html
4073570409 227985 index.html3. Use find with cksum
Although find lacks a dedicated duplicate‑file option, it can locate files by name or type and pipe them to cksum.
$ find . -name "*.html" -exec cksum {} \;
4073570409 227985 ./home.html
2819078353 228029 ./backup.html
4073570409 227985 ./index.html4. Use fslint
fslintis a dedicated duplicate‑file finder. It requires installation and adding its directory to PATH.
$ fslint .
-----------------------------------file name lint
...
----------------------------------DUPlicate files <==
home.html
index.htmlTip: add fslint to the search path:
$ export PATH=$PATH:/usr/share/fslint/fslint5. Use rdfind
rdfindsearches for redundant (identical) files and can automatically delete newer copies with the -deleteduplicates true option.
$ rdfind ~
Now scanning "/home/alvin", found 12 files.
Removed 1 files due to nonunique device and inode.
Total size 699498 bytes (683 KiB)Dry‑run mode (no actual deletion):
$ rdfind -dryrun true ~
(DRYRUN MODE) Now scanning "/home/alvin", found 12 files.
...Automatic deletion:
$ rdfind -deleteduplicates true .
Deleted 1 files.6. Use fdupes
fdupeslists duplicate files and offers many useful options; -r makes the search recursive.
$ fdupes ~
/home/alvin/UPGRADE
/home/alvin/mytwin
/home/alvin/lp.txt
/home/alvin/lp.man
/home/alvin/penguin.png
/home/alvin/penguin0.png
/home/alvin/hideme.pngCommon options are summarized in the original article’s table (image omitted).
Conclusion
Linux provides a variety of tools— diff, cksum, find, fslint, rdfind, and fdupes —that enable you to locate and safely delete duplicate files, quickly freeing up disk space.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
