Guest User

Untitled

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #!/bin/bash -e
  2.  
  3. REVISION=2
  4.  
  5. echo "Cleaner rev. ${REVISION}, tool for cleaning up caches, logs and temp files in macOS."
  6. echo "License: Creative Commons Zero v1.0 Universal"
  7. echo
  8.  
  9. function dir_is_cleanable
  10. {
  11. if [ -d "$1" ]
  12. then
  13. if [ `find "$1" -maxdepth 1 -mindepth 1 | wc -l` -eq 0 ]
  14. then
  15. false
  16. else
  17. true
  18. fi
  19. else
  20. false
  21. fi
  22. }
  23.  
  24. function cleanup_dir_content
  25. {
  26. if dir_is_cleanable "$1"
  27. then
  28. pushd "$1" > /dev/null
  29. echo "${PWD}"
  30. sudo rm -rf * || true
  31. popd > /dev/null
  32. fi
  33. }
  34.  
  35. function find_subdir_and_cleanup
  36. {
  37. find "$1" -name "$2" -type d -mindepth $3 -maxdepth $4 | while read dir
  38. do
  39. cleanup_dir_content "${dir}"
  40. done
  41. }
  42.  
  43. cleanup_dir_content "/System/Library/Caches"
  44. cleanup_dir_content "/Library/Caches"
  45. cleanup_dir_content "/System/Library/Logs"
  46. cleanup_dir_content "/Library/Logs"
  47. cleanup_dir_content "/private/var/log/asl"
  48.  
  49. cleanup_dir_content "/tmp"
  50. cleanup_dir_content "/private/var/tmp"
  51.  
  52. cleanup_dir_content "${HOME}/.Trash"
  53. cleanup_dir_content "${HOME}/.cache"
  54. cleanup_dir_content "${HOME}/Library/Caches"
  55. cleanup_dir_content "${HOME}/Library/Logs"
  56. cleanup_dir_content "${HOME}/Library/Saved Application State"
  57. cleanup_dir_content "${HOME}/Library/Application Support/CrashReporter"
  58.  
  59. cleanup_dir_content "$(getconf DARWIN_USER_CACHE_DIR)"
  60. cleanup_dir_content "$(getconf DARWIN_USER_TEMP_DIR)"
  61.  
  62. find_subdir_and_cleanup "${HOME}/Library/Containers" "Caches" 4 4
  63. find_subdir_and_cleanup "${HOME}/Library/Containers" "Logs" 4 4
Add Comment
Please, Sign In to add comment