My build of nnn with minor changes
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

74 rindas
2.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 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. ## After editiing this file you will be prompted to remove some of them.
  21. ## You can choose between removing all the commented out files, all the uncommented ones or none at all.
  22. ## Lines with double comments (##) are always ignored.
  23. ## If you choose to remove, you will be given a choice between removing with force or interactively for each file.\n
  24. " > "$tmpfile"
  25. # shellcheck disable=SC2016
  26. find . -size +0 -type f -printf "%${size_digits}s %p\n" | sort -rn | uniq -w"${size_digits}" -D | sed -E '
  27. s/^ {,12}([0-9]{,12}) (.*)$/printf "%s %s\\n" "$(md5sum "\2")" "d\1"/
  28. ' | tr '\n' '\0' | xargs -0 -n1 sh -c | sort | { uniq -w32 --all-repeated=separate; echo; } | sed -nE '
  29. h
  30. s/^(.{32}).* d([0-9]*)$/## md5sum: \1 size: \2 bytes/p
  31. g
  32. :loop
  33. N
  34. /.*\n$/!b loop
  35. p' | sed -E 's/^.{32} (.*) d[0-9]*$/\1/' >> "$tmpfile"
  36. "$EDITOR" "$tmpfile"
  37. printf "Remove commented files? (yes/no/abort) [default=a]: "
  38. read -r commented
  39. if [ "$commented" = "y" ]; then
  40. sedcmd="/^(##|[^#]).*/d; /^$/d; s/^# *(.*)$/\1/"
  41. elif [ "$commented" = "n" ]; then
  42. sedcmd="/^#.*/d; /^$/d; s/^ *(.*)$/\1/"
  43. else
  44. printf "Press any key to exit"
  45. read -r _
  46. exit
  47. fi
  48. printf "Remove with force or interactive? (f/i) [default=i]: "
  49. read -r force
  50. if [ "$force" = "f" ]; then
  51. #shellcheck disable=SC2016
  52. sed -E "$sedcmd" "$tmpfile" | tr '\n' '\0' | xargs -0 sh -c 'rm -f "$0" "$@" </dev/tty'
  53. else
  54. #shellcheck disable=SC2016
  55. sed -E "$sedcmd" "$tmpfile" | tr '\n' '\0' | xargs -0 sh -c 'rm -i "$0" "$@" </dev/tty'
  56. fi
  57. rm "$tmpfile"
  58. printf "Press any key to exit"
  59. read -r _