Advertisement
metalx1000

Find and Remove Duplicate Files with BASH

Nov 2nd, 2024 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.64 KB | None | 0 0
  1. # find all duplicate files
  2. find . ! -empty -type f -exec md5sum {} + | sort | uniq -w32 -dD
  3.  
  4. # list only first match in duplicates
  5. find . ! -empty -type f -exec md5sum {} + | sort | uniq -w32 -d
  6.  
  7. # list only the filename of first match
  8. find . ! -empty -type f -exec md5sum {} + | sort | uniq -w32 -d|cut -c 35-
  9.  
  10. #---- using fdupes
  11. # List Duplicates
  12. fdupes -r .
  13.  
  14. # -f Omit the first file in each set of matches
  15. fdupes -r -f .  
  16.  
  17. # list and select Duplicates
  18. fdupes -r -d .
  19.  
  20. # auto delete, be careful with this
  21. fdupes -r -f . | grep -v '^$' | xargs -I {} rm -v "{}"
  22.  
  23. fdupes -r -f . | grep -v '^$' |while read file;do rm -v "$file";done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement