Forum Discussion
How to Effectively Find and Delete Duplicate Files on Mac?
If you prefer using the command line to find and delete duplicate files on your Mac, you can use a combination of terminal commands and scripting. Below is a step-by-step guide to help you achieve this:
Step 1: Use the cd command to navigate to the folder where you want to search for duplicates. This will take you to the Documents folder. Replace ~/Documents with the path to the folder you want to scan.
Step 2: You can use the find and md5 commands to fina and delete duplicate files on Mac based on their content (MD5 hash). Here's a script to do this:
#!/bin/bash
# Directory to search (change this to your target directory)
DIRECTORY="."
# Create a temporary file to store MD5 hashes
TMP_FILE=$(mktemp)
# Find all files in the directory, calculate their MD5 hashes, and store in the temp file
find "$DIRECTORY" -type f -exec md5 {} \; | sort > "$TMP_FILE"
# Identify duplicates by comparing MD5 hashes
awk '{
if ($1 == prev_hash) {
print "Duplicate found: " $2 " and " prev_file
}
prev_hash = $1
prev_file = $2
}' "$TMP_FILE"
# Clean up the temporary file
rm "$TMP_FILE"
This script will list all duplicate files in the specified directory based on their MD5 hash. Once you've identified the duplicates, you can manually delete them using the rm command.
P.S. If you're confident and want to automate the deletion of duplicates, you can modify the script to delete duplicates automatically.