On windows it’s popular for different malware to create autorun.inf file on all available drives to exploit the Autorun feature. I’ve heard modern versions of Windows restrict the behavior or even disable it by default, but I don’t know for sure. Anyway, it’s better to create an empty autorun.inf directory in the flash drive filesystem’s root. (I believe) most of malware will not remove it and create their file, but just silently fail.
On OS X it’s very annoying that the system creates a couple of directories for its own use, such as .Spotlight and .fseventsd. So, touch these regular files: .Trashes and .metadata_never_index. Also, creating a file no_log in .fseventsd directory prevents the system from writing filesystem logs to the device.
I’ve also created a simple script that does the steps described above and removes unnecessary files and directories:
Script to remove auxiliary files created by OS X and windows (stop_annoying_flash_drive.sh)download
#!/bin/bashecho"Warning! Some files may be deleted from your flash drive! Make sure you have a backup!"DST_DIR=${1:?"Please specify the target directory of flash drive"}[[ -w "${DST_DIR}"]]||{echo"${DST_DIR} is not writable!";exit1;}# NB! Always use quotes when specifying paths for rm command!RM_OPTS="-rfv"MKDIR_OPTS="-v"### for OS X #### create .metadata_never_index filerm ${RM_OPTS}"${DST_DIR}/.metadata_never_index"touch "${DST_DIR}/.metadata_never_index"# create .Trashes filerm ${RM_OPTS}"${DST_DIR}/.Trashes"touch "${DST_DIR}/.Trashes"# create .fseventsd/no_log filerm ${RM_OPTS}"${DST_DIR}/.fseventsd"mkdir ${MKDIR_OPTS}"${DST_DIR}/.fseventsd"touch "${DST_DIR}/.fseventsd/no_log"# remove remnantsrm ${RM_OPTS}"${DST_DIR}/.Spotlight"rm ${RM_OPTS}"${DST_DIR}/.TemporaryItems"rm ${RM_OPTS}"${DST_DIR}/._.TemporaryItems"### for windows #### create autorun.inf directoryrm ${RM_OPTS}"${DST_DIR}/autorun.inf"mkdir ${MKDIR_OPTS}"${DST_DIR}/autorun.inf"
NB! I’m not responsible if the script deletes some necessary files. Use it on your own risk! Always make backups of your data! Use it like this: