Skip to content

Instantly share code, notes, and snippets.

@weaming
Last active August 14, 2022 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaming/a0dd580f50ead281a7152ba075e16afe to your computer and use it in GitHub Desktop.
Save weaming/a0dd580f50ead281a7152ba075e16afe to your computer and use it in GitHub Desktop.
Shell script to clean my android SDCard
# Preconditions:
# 1. Install adb drivers on your computer
# 2. Append the path of 'adb.exe' to the PATH environment variable
# 3. run "adb devices" to run adb ademon in background and list all connected devices
# 4. run "adb shell" get in the shell interface
cd /sdcard
# list all directories in current path, whose size is less than 100 KB
#du -d 1 | grep -v '\./\.' | awk '$1 < 100 {print $0}'
# delete them, with a log in file deleted.log
rm -rf $(du -d 1 | grep -v '\./\.' | awk '$1 < 100 {print $2}' | tee deleted-cache.log)
# delete cache dir or file whose access time is 10 days ago
find . -iname '*cache*' -atime +10 -delete -print | tee deleted-cache-atime-10days-ago.log
# delete cache dir or file whose create time is 10 days ago
find . -iname '*cache*' -ctime +10 -delete -print | tee deleted-cache-ctime-10days-ago.log
# delete empty directory
find . -maxdepth 5 -type d -print -exec rmdir {} 2>/dev/null && echo {} \;
# fstrim
# Need install busybox first and root privilege
# run "su" first!
fstrim -v /data && fstrim -v /system && fstrim -v /cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment