My build of nnn with minor changes
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

47 řádky
1.2 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
  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. # shellcheck disable=SC2016
  19. find . -size +0 -type f -printf "%${size_digits}s %p\n" | sort -rn | uniq -w"${size_digits}" -D | sed -E '
  20. s/^ {,12}([0-9]{,12}) (.*)$/printf "%s %s\\n" "$(md5sum "\2")" "d\1"/
  21. ' | tr '\n' '\0' | xargs -0 -n1 sh -c | sort | { uniq -w32 --all-repeated=separate; echo; } | sed -nE '
  22. h
  23. s/^(.{32}).* d([0-9]*)$/md5sum: \1 size: \2 bytes/p
  24. g
  25. :loop
  26. N
  27. /.*\n$/!b loop
  28. p' | sed -E 's/^.{32} (.*) d[0-9]*$/\1/' > "$tmpfile"
  29. "$EDITOR" "$tmpfile"
  30. cat "$tmpfile"
  31. # shellcheck disable=SC2016
  32. sed -e 's/md5sum.*//' "$tmpfile" | tr '\n' '\0' | xargs -0 sh -c 'rm -i "$0" "$@" < /dev/tty'
  33. rm "$tmpfile"
  34. printf "Press any key to exit"
  35. read -r _