Skip to content

Instantly share code, notes, and snippets.

@mrowell
Last active March 3, 2017 05:36
Show Gist options
  • Save mrowell/48c5d1301af89b821c53 to your computer and use it in GitHub Desktop.
Save mrowell/48c5d1301af89b821c53 to your computer and use it in GitHub Desktop.
Remove Phantom Folders from /Volumes
#!/bin/bash
for path in /Volumes/*; do
echo "checking $path"
if [[ -d "$path" ]] && [[ "$path" != "/Volumes/MobileBackups" ]] ; then
notADisk=`diskutil list "$path" | grep -c "Could not find disk"`
notAShare=`df -H | grep -c "$path"`
if [[ "$notADisk" == 1 ]] && [[ "$notAShare" == 0 ]] ; then
DATE=`date +%Y-%m-%d-%H%M%S`
if ! [[ -e "/Users/Shared/Volumes-$DATE" ]] ; then
mkdir "/Users/Shared/Volumes-$DATE"
fi
echo "Moving $path to /Users/Shared/Volumes-$DATE/"
mv "$path" "/Users/Shared/Volumes-$DATE/"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment