Skip to content

Instantly share code, notes, and snippets.

@simbamangu
Created June 12, 2024 06:29
Show Gist options
  • Save simbamangu/ce13d3fd57a9216dec7de20439d55fbb to your computer and use it in GitHub Desktop.
Save simbamangu/ce13d3fd57a9216dec7de20439d55fbb to your computer and use it in GitHub Desktop.
Back up WhatsApp media and delete older files

To remove old WhatsApp media from an Android phone connected by USB cable (with developer options enabled).

Use BetterAdbSync:

pip install BetterADBSync

Then run the following to back up to a folder in your home directory:

adbsync —show-progress pull sdcard/Android/media/com.whatsapp/WhatsApp/Media/ ~/Documents/WhatsApp\ Media/

Afterwards use adb shell then run the following in the shell on your Android to delete media files older than 180 days:

find sdcard/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp\ Images/ -type f -mtime +180 -delete
find sdcard/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp\ Video/ -type f -mtime +180 -delete
find sdcard/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp\ Documents/ -type f -mtime +180 -delete
exit

Modify -mtime +180 to change the age of the deleted files in days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment