Find Duplicate Files using Mac Terminal Command


There are tons of free and paid apps available for Mac to identify duplicate files and clean them, but do you know you can identify and delete duplicate files easily using the Mac Terminal, all you need is a package called fdupes

You can download this package using brew

brew install fdupes

GitHub: https://github.com/adrianlopezroche/fdupes

⛏️ Installing Brew on Mac

Example: Find all duplicates in the Downloads folder
% fdupes -r -S Downloads

2513563 bytes each:
Downloads/mysql-connector-java-8.0.30/mysql-connector-java-8.0.30.jar
Downloads/mysql-connector-java-8.0.30.jar

1113 bytes each:                          
Downloads/2020101_Image.png
Downloads/temp.png


24958 bytes each:                          
Downloads/college-trip.mp4
Downloads/college-trip-copy.mp4

As you can see, I was able to get duplicate files - Images, Software, and Videos with the size they occupy!

Few useful options
-r --recurse     :for every directory given follow subdirectories encountered within
-s --symlinks    :follow symlinks
-G --minsize=SIZE      :consider only files greater than or equal to SIZE bytes
-L --maxsize=SIZE      :consider only files less than or equal to SIZE bytes
-A --nohidden        :exclude hidden files from consideration
-S --size          :show size of duplicate files

Deleting the files

Use -d as an option with the command, Note: You should be extra cautious while using this command to delete file,

% fdupes -d -r /Downloads/myFiles

You will get an interactive screen for duplicate files asking which one to keep.

Find and delete files using Mac Terminal Command


Have Questions? Post them here!
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.