Skip to content

Instantly share code, notes, and snippets.

@smaddock
Forked from bwmorales/fileKiller.sh
Last active July 10, 2018 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smaddock/44e01dc529e081eb6be976f8774797e4 to your computer and use it in GitHub Desktop.
Save smaddock/44e01dc529e081eb6be976f8774797e4 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
SYSTEM_FILES=(
'/Applications/Google Chrome.app'
)
USER_FILES=(
'~/Library/Application Support/Google/Chrome'
'~/Library/Caches/Google/Chrome'
)
LOG_FILE='/Library/Addigy/logs/file-removal.log'
removeFiles(){
/usr/bin/printf "%s Removing: '%s'\n" "$(/bin/date "+%Y/%m/%d %H:%M:%S")" "$*" | tee -a "$LOG_FILE"
/bin/rm -Rf "${TARGET_FILE}"
}
LOG_DIR="$(dirname "$LOG_FILE")"
if [[ ! -e $LOG_DIR ]]; then
/bin/mkdir -p "$LOG_DIR"
fi
if [[ ! -e $LOG_FILE ]]; then
/usr/bin/touch "$LOG_FILE"
fi
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