My build of nnn with minor changes
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

71 wiersze
1.9 KiB

  1. #!/usr/bin/env sh
  2. # Description: List non-empty duplicate files in the current directory (based on size followed by MD5)
  3. #
  4. # Source: https://www.commandlinefu.com/commands/view/3555/find-duplicate-files-based-on-size-first-then-md5-hash
  5. #
  6. # Dependencies: find md5sum sort uniq xargs gsed
  7. #
  8. # Note: bash compatible required for mktemp
  9. #
  10. # Shell: bash
  11. # Authors: syssyphus, KlzXS
  12. # If the size of a file has more that $size_digits digits the file will be misplaced
  13. # 12 digits fit files up to 931GiB
  14. EDITOR="${EDITOR:-vi}"
  15. TMPDIR="${TMPDIR:-/tmp}"
  16. size_digits=12
  17. tmpfile=$(mktemp "$TMPDIR/.nnnXXXXXX")
  18. printf "\
  19. ## This is an overview of all duplicate files found.
  20. ## Comment out the files you wish to remove. You will be given an option to cancel.
  21. ## Lines with double comments (##) are ignored.
  22. ## You will have the option to remove the files with force or interactively.\n
  23. " > "$tmpfile"
  24. # shellcheck disable=SC2016
  25. find . -size +0 -type f -printf "%${size_digits}s %p\n" | sort -rn | uniq -w"${size_digits}" -D | sed -E '
  26. s/^ {,12}([0-9]{,12}) (.*)$/printf "%s %s\\n" "$(md5sum "\2")" "d\1"/
  27. ' | tr '\n' '\0' | xargs -0 -n1 sh -c | sort | { uniq -w32 --all-repeated=separate; echo; } | sed -nE '
  28. h
  29. s/^(.{32}).* d([0-9]*)$/## md5sum: \1 size: \2 bytes/p
  30. g
  31. :loop
  32. N
  33. /.*\n$/!b loop
  34. p' | sed -E 's/^.{32} (.*) d[0-9]*$/\1/' >> "$tmpfile"
  35. "$EDITOR" "$tmpfile"
  36. printf "Remove commented files? (yes/no) [default=n]: "
  37. read -r commented
  38. if [ "$commented" = "y" ]; then
  39. sedcmd="/^(##|[^#]).*/d; /^$/d; s/^# *(.*)$/\1/"
  40. else
  41. printf "Press any key to exit"
  42. read -r _
  43. exit
  44. fi
  45. printf "Remove with force or interactive? (f/i) [default=i]: "
  46. read -r force
  47. if [ "$force" = "f" ]; then
  48. #shellcheck disable=SC2016
  49. sed -E "$sedcmd" "$tmpfile" | tr '\n' '\0' | xargs -0 -r sh -c 'rm -f "$0" "$@" </dev/tty'
  50. else
  51. #shellcheck disable=SC2016
  52. sed -E "$sedcmd" "$tmpfile" | tr '\n' '\0' | xargs -0 -r sh -c 'rm -i "$0" "$@" </dev/tty'
  53. fi
  54. rm "$tmpfile"
  55. printf "Press any key to exit"
  56. read -r _