Skip to content

Instantly share code, notes, and snippets.

@bwmorales
Last active July 10, 2018 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bwmorales/1b0fc8ee177a55b3506cdc6661555f5c to your computer and use it in GitHub Desktop.
Save bwmorales/1b0fc8ee177a55b3506cdc6661555f5c to your computer and use it in GitHub Desktop.
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