Skip to content

Clean drive before unmount

How to clean flash drive and delete all hidden (dot) files on mac before unmount? It’s simple, save follow commands as flash:

if [ -n "$1" ]; then
read -r -p "Clean /Volumes/$1/ and unmount? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
find /Volumes/$1/ -name '._*' -type f -delete
rm -rf /Volumes/$1/.Spotlight-V100/
rm -rf /Volumes/$1/.Trashes/
diskutil unmount /Volumes/$1/
echo "Done..."
echo "Flash drive name missing"

Then change the access mode of a file chmod +x flash. To unmount a clean flash drive just run ./flash Flashka (Flashka is name od drive).