Created
December 24, 2020 11:09
-
-
Save timabell/c1613f4b5156c42e5e1f560a54eed420 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Clear older photos and videos of android phone. | |
# Combined with https://syncthing.net/ | |
# Howto: | |
# | |
# *Warning* make sure you have good backups and multiple copies of things first! | |
# | |
# 1) Install synthing on the phone and a laptop. Configure sync of at least DCIM folder. | |
# 2) Run this script on the laptop (update paths for your devices). | |
# 3) Watch as syncthing magically deletes old pics off your phone freeing up valuable space. Hurrah. | |
# http://serverfault.com/a/505953/15016 | |
phone_base="/home/tim/oneplus5t-home/" | |
pics_base="/home/tim/Pictures/oneplus5t/" | |
camera="DCIM/Camera/" | |
whatsapp_vid="WhatsApp/Media/WhatsApp Video/" | |
whatsapp_vid_sent="WhatsApp/Media/WhatsApp Video/Sent/" | |
whatsapp_img="WhatsApp/Media/WhatsApp Images/" | |
whatsapp_img_sent="WhatsApp/Media/WhatsApp Images/Sent/" | |
# https://stackoverflow.com/a/14447471/10245 | |
dryrun=false | |
while getopts "n" opt; do | |
case $opt in | |
n) | |
echo "-n was triggered for dry run" | |
dryrun=true | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
echo "laptop disk space:" | |
df -h "$pics_base" | |
for item in "$camera" "$whatsapp_vid" "$whatsapp_vid_sent" "$whatsapp_img" "$whatsapp_img_sent" ; do | |
from="$phone_base$item" | |
to="$pics_base$item" | |
echo "clearing down $from >> $to" | |
echo "before move:" | |
du -sh "$from" "$to" | |
if [ $dryrun == true ]; then | |
# list (preview) | |
find "$from" -maxdepth 1 -mtime +90 -type f -exec echo "{} >> $to" \; | |
else | |
mkdir -p "$to" | |
echo "moving..." | |
find "$from" -maxdepth 1 -mtime +90 -type f -exec mv -n "{}" "$to" \; | |
echo "after move:" | |
du -sh "$from" "$to" | |
fi | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment