Created
January 17, 2011 20:58
-
-
Save timothykim/783472 to your computer and use it in GitHub Desktop.
Simple bash script for Mac OS X that cleans USB drives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Simple bash script for Mac OS X that cleans USB drives and adds some default files so that | |
# | |
# 1. Trash folder doesn't get created | |
# 2. Spotlight indexing is prevented | |
# 3. Filesystem logs are not created | |
# | |
# Usage: | |
# | |
# $ usb_clean [diskname] | |
# | |
# You may get the name of your USB drive by running: | |
# | |
# $ diskutil list | |
# | |
# | |
# | |
# For example: | |
# | |
# $ diskutil list | |
# /dev/disk1 | |
# #: TYPE NAME SIZE IDENTIFIER | |
# 0: GUID_partition_scheme *4.0 GB disk1 | |
# 1: EFI 209.7 MB disk1s1 | |
# 2: Microsoft Basic Data USBDRIVE 3.8 GB disk1s2 | |
# | |
# $ clean_usb disk1 | |
TARGET=$* | |
read -n1 -p "You are about to complete erase the contents of /dev/${TARGET}. Are you suer? [y/N] " | |
echo | |
case $REPLY in | |
y | Y) | |
echo "Erasing all the data in /dev/${TARGET}" | |
;; | |
* ) | |
echo "Aborting..." | |
exit | |
;; | |
esac | |
diskutil eraseDisk MS-DOS "USBDrive" ${TARGET} | |
rm -rf /Volumes/USBDRIVE/.Spotlight-V100 | |
rm -rf /Volumes/USBDRIVE/.Trashes | |
rm -rf /Volumes/USBDRIVE/.fseventsd | |
touch /Volumes/USBDrive/.Trashes | |
touch /Volumes/USBDrive/.metadata_never_index | |
mkdir /Volumes/USBDrive/.fseventsd | |
touch /Volumes/USBDrive/.fseventsd/no_log | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment