diff --git a/bin/clean b/bin/clean index 1037d88..4b3162c 100755 --- a/bin/clean +++ b/bin/clean @@ -16,7 +16,7 @@ ########## _version() { cat <&2 + exit 1 +fi + print Clean APT... -sudo apt-get "${quiet[@]}" "${quiet[@]}" autoremove --purge --yes -sudo apt-get "${quiet[@]}" "${quiet[@]}" clean --yes +apt-get "${quiet[@]}" "${quiet[@]}" autoremove --purge --yes +apt-get "${quiet[@]}" "${quiet[@]}" clean --yes print APT cleaned. print Clean snap... for line in $(snap list --all | awk '/disabled/{print $1, $3}'); do IFS=$' \t' read -r snapname revision <<< "${line}" # shellcheck disable=SC2024 - sudo snap remove "${snapname}" --purge --revision="${revision}" > "${redirection}" + snap remove "${snapname}" --purge --revision="${revision}" > "${redirection}" done print Snaps cleaned. print Rotate journal... -sudo journalctl --flush --rotate --vacuum-time="${journal_retention}" "${quiet[@]}" +journalctl --flush --rotate --vacuum-time="${journal_retention}" "${quiet[@]}" print Journal rotated. print -n Flush system caches... -[[ -d /var/cache ]] && sudo find /var/cache -mindepth 1 -delete -[[ -d /var/lib/snapd/cache ]] && sudo find /var/lib/snapd/cache -mindepth 1 -delete +[[ -d /var/cache ]] && find /var/cache -mindepth 1 -delete +[[ -d /var/lib/snapd/cache ]] && find /var/lib/snapd/cache -mindepth 1 -delete print Done. -# User caches -for user in "${users[@]}"; do - if ! homedir=$(getent passwd "${user}" | cut -d: -f6); then - echo User not exits: "${user}" >&2 - exit 1 - fi - - print Clean-up for "${user}..." - - print -n Empty trash bin... - sudo test -d "${homedir}/.local/share/Trash" && sudo find "${homedir}/.local/share/Trash" -mindepth 1 -delete - print Done. - - print -n Flush Chrome cache... - sudo test -d "${homedir}/.config/google-chrome" && sudo find "${homedir}/.config/google-chrome" -mindepth 1 -delete - print Done. - - print -n "Flush gdfuse (Google Drive FS) cache..." - sudo test -d "${homedir}/.gdfuse/${user}/cache" && sudo find "${homedir}/.gdfuse/${user}/cache" -mindepth 1 -delete - print Done. - - print -n Flush Spotify cache... - sudo test -d "${homedir}/snap/spotify/common/.cache" && sudo find "${homedir}/snap/spotify/common/.cache" -mindepth 1 -delete - print Done. - - print Cleanup finished for "${user}." -done - exit 0 diff --git a/docs/bin.md b/docs/bin.md index 1bde272..2466b31 100644 --- a/docs/bin.md +++ b/docs/bin.md @@ -121,13 +121,15 @@ Clean-up temporary and other not needed files to free up disk space: - Remove unused `apt` packages - Remove old snaps - Rotate system journal (keep 2 weeks of logs) -- Delete caches (various system & user caches) +- Flush system caches !!! info This script is completely standalone, no bootstrapping is required! Perfect to run weekly by cron. + Needs root permissions. + **Usage** ``` @@ -138,8 +140,6 @@ OPTIONS -j, --journal [TIME] Remove journal older than this time specified with the usual "s", "m", "h", etc. suffixes. Defaults to 2 weeks (2w). --u, --user [USER] Clear temp files in user's HOME also. - Can be specified multiple times to clean more user HOME. -q, --quiet Suppress non-error messages -h, --help Display this help -v, --version Print version info