Skip to content

Instantly share code, notes, and snippets.

@jfeilbach
Last active April 15, 2020 16:30
Show Gist options
  • Save jfeilbach/6b8739a58533ff3128042195576c9dc0 to your computer and use it in GitHub Desktop.
Save jfeilbach/6b8739a58533ff3128042195576c9dc0 to your computer and use it in GitHub Desktop.
/etc/cron.daily/clean_mac_files.cron
#!/bin/bash
# 22 Mar 2020
# version .4 Added more logging
# Version .3 Fixed recursive directory deletes failing
# Version .2 - remove .DS_Store files and ._* files
#
SECONDS=0
log=/var/log/syslog
echo "Starting removing Mac specific files..." 2>&1 | /usr/bin/logger -t mac_files
find /mnt/ -name ".DS_Store" -print -delete
find /mnt/ -name "._*" -print -delete
find /mnt/ -name ".TemporaryItems" -exec rm -rfv "{}" \;
find /mnt/ -name ".Spotlight-V100" -print -delete
find /mnt/ -name ".apdisk" -print -delete
find /mnt/ -name ".Trashes" -print -delete
find /mnt/ -name ".fseventsd" -print -delete
find /mnt/ -name "._.Trashes" -print -delete
find /mnt/ -name "Thumbs.db" -print -delete
#find /mnt/ -name ".AppleDesktop" -print -delete | tee ${log}
find /mnt/ -name ".AppleDesktop" -exec rm -rfv "{}" \;
find /mnt/ -name ".AppleDB" -print -delete
find /mnt/ -name ".LSOverride" -print -delete
find /mnt/ -name ".AppleDouble" -print -delete
echo "Finished removing Mac specific files." 2>&1 | /usr/bin/logger -t mac_files
displaytime () {
local T=$SECONDS
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
[[ $D > 0 ]] && printf '%d days ' $D
[[ $H > 0 ]] && printf '%d hours ' $H
[[ $M > 0 ]] && printf '%d minutes ' $M
[[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and '
printf '%d seconds\n' $S
}
echo "Took $(displaytime) to complete ${0}." 2>&1 | /usr/bin/logger -t mac_files
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment