Skip to content

Instantly share code, notes, and snippets.

@ccraig
Last active August 29, 2015 14:02
Show Gist options
  • Save ccraig/1f81576e0f6976357c95 to your computer and use it in GitHub Desktop.
Save ccraig/1f81576e0f6976357c95 to your computer and use it in GitHub Desktop.
Recursively removes all .DS_Store files from a given directory. Usage: ds_destroyer [-n] directory. Shamelessly stole the -n flag from rsync
#!/bin/bash
dry_run=$1
dir=$2
if [ $# == 1 ]; then
dir=$1
if [ ! -d $dry_run ]; then
echo "Directory '$dir' does not exist"
echo "Usage: ds_destroyer [-n] <directory>"
exit 1
fi
else
if [ "$dry_run" != "-n" ] || [ ! -d $dir ]; then
if [ ! -d $dir ]; then
echo "Directory '$dir' does not exist"
fi
echo "Usage: ds_destroyer [-n] <directory>"
exit 1
fi
fi
for ds in `find $dir -name '.DS_Store'`; do
if [ "$dry_run" != "-n" ]; then
echo "Removing: $ds"
rm $ds
else
echo "Would Remove: $ds"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment