Delete suspicious directories and files by using the find command

Abstract

Delete suspicious directories and files by using the find command on Ubuntu 12.04.
The following commands are useful to sanitize files which have been downloaded from a suspicious site.

Commands

# Set a target directory.
$ TARGET_DIR='/home/shinya/suspicious'


# Delete symbolic links
$ find "${TARGET_DIR}" -type l -print -exec rm {} \;


# Delete directories whose name starts with a dot such as .git and .emacs.d.
$ find "${TARGET_DIR}" -type d -name '.*' -print -exec rm -r {} +
# Delete files whose name starts with a dot such as .gitignore and .emacs
$ find "${TARGET_DIR}" -type f -name '.*' -print -exec rm {} \;


# Delete empty directories.
$ find "${TARGET_DIR}" -type d -empty -delete


# Delete suspicious and unnecessary files.
# The following matches are case insensitive (-iname).
# Use -name for case sensitive matches.
$ find "${TARGET_DIR}" -type f -iname '*.exe' -print -exec rm {} \;
$ find "${TARGET_DIR}" -type f -iname 'Thumbs.db' -print -exec rm {} \;
$ find "${TARGET_DIR}" -type f -iname 'a.out' -print -exec rm {} \;