Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

Find Duplicate Files Using the Command Line on a Mac (or Linux)

In this video I use a number of different command line utilities to identify duplicate files.

Print Working Directory
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pwd
pwd
pwd
Find All Files in Current Directory
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
find ./
find ./
find ./
Find Only Files (no directories)
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
find ./ -type f
find ./ -type f
find ./ -type f
Find Only Non-empty Files (no directories)
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
find ./ -type f -not -empty
find ./ -type f -not -empty
find ./ -type f -not -empty
Find Only Non-empty Files and Exclude Files in Library Directory (no directories)
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
find ./ -type f -not -empty -not -path './/Library/*'
find ./ -type f -not -empty -not -path './/Library/*'
find ./ -type f -not -empty -not -path './/Library/*'
Get md5sum of Find Results (Mac)
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
find ./ -type f -not -empty -not -path './/Library/*' -exec md5 -r {} \;
find ./ -type f -not -empty -not -path './/Library/*' -exec md5 -r {} \;
find ./ -type f -not -empty -not -path './/Library/*' -exec md5 -r {} \;
Get md5sum of Find Results (Linux)
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
find ./ -type f -not -empty -not -path './/Library/*' -exec md5sum {} \;
find ./ -type f -not -empty -not -path './/Library/*' -exec md5sum {} \;
find ./ -type f -not -empty -not -path './/Library/*' -exec md5sum {} \;

Note: use “md5 -r” on Mac and “md5sum” on Linux in any future command.

Write md5sums to File
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
find ./ -type f -not -empty -not -path './/Library/*' -exec md5 -r {} \; > file_list.txt
find ./ -type f -not -empty -not -path './/Library/*' -exec md5 -r {} \; > file_list.txt
find ./ -type f -not -empty -not -path './/Library/*' -exec md5 -r {} \; > file_list.txt
Count the Number of Lines in file_list.txt
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
wc -l file_list.txt
wc -l file_list.txt
wc -l file_list.txt
Get list of md5sums for Jpeg Files
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
find ./ -type f -not -empty -not -path './/Library/*' -iname '*.jpg' -exec md5 -r {} \; > file_list.txt
find ./ -type f -not -empty -not -path './/Library/*' -iname '*.jpg' -exec md5 -r {} \; > file_list.txt
find ./ -type f -not -empty -not -path './/Library/*' -iname '*.jpg' -exec md5 -r {} \; > file_list.txt
View first 10 Lines of a File
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
head -n 10 file_list.txt
head -n 10 file_list.txt
head -n 10 file_list.txt
View first 20 Lines of File
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
head -n 20 file_list.txt
head -n 20 file_list.txt
head -n 20 file_list.txt
Sort file_list.txt
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sort file_list.txt > file_list_sort.txt
sort file_list.txt > file_list_sort.txt
sort file_list.txt > file_list_sort.txt
Output file_list_sort.txt to Terminal
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cat file_list_sort.txt
cat file_list_sort.txt
cat file_list_sort.txt
Isolate the md5sums
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cat file_list_sort.txt | cut -d ' ' -f1
cat file_list_sort.txt | cut -d ' ' -f1
cat file_list_sort.txt | cut -d ' ' -f1
Count Each md5sum
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c
Remove md5sums of Files that only have 1 Copy
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^ 1 '
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^ 1 '
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^   1 '
Swap md5sum and Count
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^ 1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }'
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^ 1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }'
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^   1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }'
Sort md5sum and Count List by Hash
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^ 1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }' | sort
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^ 1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }' | sort
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^   1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }' | sort
Write Results to File
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^ 1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }' | sort > file_counts.txt
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^ 1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }' | sort > file_counts.txt
cat file_list_sort.txt | cut -d ' ' -f1 | uniq -c | grep -v '^   1 ' | awk '{ t=$1 ; $1=$2; $2=t; print }' | sort > file_counts.txt
Join File List to md5sum Counts
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
join -1 1 -2 1 file_counts.txt file_list_sort.txt
join -1 1 -2 1 file_counts.txt file_list_sort.txt
join -1 1 -2 1 file_counts.txt file_list_sort.txt
Sort Joined Results
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
join -1 1 -2 1 file_counts.txt file_list_sort.txt |sort -k2,2 -n -k1,1
join -1 1 -2 1 file_counts.txt file_list_sort.txt |sort -k2,2 -n -k1,1
join -1 1 -2 1 file_counts.txt file_list_sort.txt |sort -k2,2 -n -k1,1
Save Joined Results to a File
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
join -1 1 -2 1 file_counts.txt file_list_sort.txt |sort -k2,2 -n -k1,1 > file_dups.txt
join -1 1 -2 1 file_counts.txt file_list_sort.txt |sort -k2,2 -n -k1,1 > file_dups.txt
join -1 1 -2 1 file_counts.txt file_list_sort.txt |sort -k2,2 -n -k1,1 > file_dups.txt

Leave a comment

Your email address will not be published. Required fields are marked *