Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -e
- REVISION=2
- echo "Cleaner rev. ${REVISION}, tool for cleaning up caches, logs and temp files in macOS."
- echo "License: Creative Commons Zero v1.0 Universal"
- echo
- function dir_is_cleanable
- {
- if [ -d "$1" ]
- then
- if [ `find "$1" -maxdepth 1 -mindepth 1 | wc -l` -eq 0 ]
- then
- false
- else
- true
- fi
- else
- false
- fi
- }
- function cleanup_dir_content
- {
- if dir_is_cleanable "$1"
- then
- pushd "$1" > /dev/null
- echo "${PWD}"
- sudo rm -rf * || true
- popd > /dev/null
- fi
- }
- function find_subdir_and_cleanup
- {
- find "$1" -name "$2" -type d -mindepth $3 -maxdepth $4 | while read dir
- do
- cleanup_dir_content "${dir}"
- done
- }
- cleanup_dir_content "/System/Library/Caches"
- cleanup_dir_content "/Library/Caches"
- cleanup_dir_content "/System/Library/Logs"
- cleanup_dir_content "/Library/Logs"
- cleanup_dir_content "/private/var/log/asl"
- cleanup_dir_content "/tmp"
- cleanup_dir_content "/private/var/tmp"
- cleanup_dir_content "${HOME}/.Trash"
- cleanup_dir_content "${HOME}/.cache"
- cleanup_dir_content "${HOME}/Library/Caches"
- cleanup_dir_content "${HOME}/Library/Logs"
- cleanup_dir_content "${HOME}/Library/Saved Application State"
- cleanup_dir_content "${HOME}/Library/Application Support/CrashReporter"
- cleanup_dir_content "$(getconf DARWIN_USER_CACHE_DIR)"
- cleanup_dir_content "$(getconf DARWIN_USER_TEMP_DIR)"
- find_subdir_and_cleanup "${HOME}/Library/Containers" "Caches" 4 4
- find_subdir_and_cleanup "${HOME}/Library/Containers" "Logs" 4 4
Add Comment
Please, Sign In to add comment