How to Quickly Find Duplicate Files on Linux Using Find and dupeGuru
This guide shows step‑by‑step Linux techniques—including a powerful Find‑pipeline and the dupeGuru tool—to locate and list duplicate files by size and MD5, with full command explanations and handling of Windows line‑ending issues.
Method 1: Using the Find Command
This section extends the powerful find utility by combining it with other basic Linux commands such as xargs to create an unlimited range of command‑line functions, for example quickly listing duplicate files in a directory tree.
find -not -empty -type f -printf "%s
" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separatefind -not -empty -type f -printf "%s\n" – lists all non‑empty regular files and prints their sizes.
sort -rn – sorts the sizes in reverse numeric order.
uniq -d – keeps only the duplicated size entries.
uniq -w32 --all-repeated=separate – compares the first 32 bytes of the MD5 hash to filter duplicate files.
Method 2: Using the dupeGuru Tool
dupeGuru is a cross‑platform application (Linux, Windows, macOS) that can locate duplicate files by size, MD5, or filename. Ubuntu users can install it via a PPA:
sudo add-apt-repository ppa:hsoft/ppa
sudo apt-get update
sudo apt-get install dupeguru*Method 3: Using Find Command Parsing
When you need to find duplicate text files (e.g., game scripts) for translation, a shell script can automate the process.
Copy the following pipeline into the target directory:
find -not -empty -type f -printf "%s
" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate | cut -b 36-The pipeline works as follows: find -not -empty -type f -printf "%s\n" Outputs the size of every non‑empty regular file. sort -rn Sorts sizes in descending order. uniq -d Keeps only duplicated size values. xargs -I{} -n1 find -type f -size {}c -print0 Finds files matching each duplicated size, using a null‑terminated list to handle spaces. xargs -0 md5sum Computes MD5 hashes for those files. uniq -w32 --all-repeated=separate Groups lines with identical first 32 characters (the MD5 hash). cut -b 36- Removes the MD5 part to keep only the file paths.
Store the final output in result.txt:
find -not -empty -type f -printf "%s
" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate | cut -b 36- > result.txtOn Windows, convert Linux line endings (\n) to Windows style (\r\n):
cat result.txt | cut -c 36- | tr -s '
'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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
