Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List files that you want to assasinate in every user's home directory, as well as some system files, on macOS.
#!/bin/bash
USER_FILES=(
'~/Library/Caches/Google/Chrome'
'/Library/Application Support/Google/Chrome/Default/Application Cache'
'Library/Application Support/Google/Chrome/Default/Cookies'
' '
)
SYSTEM_FILES=(
)
LOG_FILE='/Library/Addigy/logs/file-removal.log'
removeFiles(){
logFileRemoval "${TARGET_FILE}"
# /bin/rm -Rf "${TARGET_FILE}"
}
logFileRemoval(){
if [[ ! -e $LOG_FILE ]]; then
/usr/bin/touch "$LOG_FILE"
fi
/usr/bin/printf "%s Removing: '%s'\n" "$(/bin/date "+%Y/%m/%d %H:%M:%S")" "$*" | tee -a "$LOG_FILE"
}
OIFS="$IFS"
IFS=$'\n'
for USER in $(/usr/bin/dscl . list /Users UniqueID | /usr/bin/awk '$2 >= 500 {print $1}'); do
HOME_DIR=$(/usr/bin/dscacheutil -q user -a name $USER | /usr/bin/grep -E '^dir: ' | /usr/bin/awk '{ print $2 }')
export HOME_DIR
for FILE_ABSTRACTION in "${USER_FILES[@]}"; do
FILE_ABSTRACTION="$(/usr/bin/printf "$FILE_ABSTRACTION" | /usr/bin/sed 's_^\~__' | /usr/bin/sed 's_^/__')"
TARGET_FILE="${HOME_DIR}/${FILE_ABSTRACTION}"
if [[ $FILE_ABSTRACTION != '' ]]; then
removeFiles "$TARGET_FILE"
fi
done
done
for TARGET_FILE in "${SYSTEM_FILES[@]}"; do
removeFiles "$TARGET_FILE"
done
IFS="$OIFS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment