Skip to content

Instantly share code, notes, and snippets.

@brandonpittman
Created June 6, 2014 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonpittman/f4cfeef3cccf530ac232 to your computer and use it in GitHub Desktop.
Save brandonpittman/f4cfeef3cccf530ac232 to your computer and use it in GitHub Desktop.
recursively delete .DS_Store files
#!/bin/bash
# This script removes all annoying .DS_Store'
s recursively from you Mac
# The first argument is the starting directory
# from: https://coderwall.com/p/oxxwca
search_folder () {
dir="$1"
if [ -d "$dir" ];then
file=''
for file in $(ls -a "$dir");do
#echo $dir / $file
if [ "$file" != "." ] && [ "$file" != ".." ];then
if [ -d "$dir/$file" ];then
search_folder "$dir/$file"
elif [ "$file" == ".DS_Store" ];then
echo "$dir/$file"
mkdir -p "$HOME/.Trash/DS_Store/$dir"
mv "$dir/$file" "$HOME/.Trash/DS_Store/$dir/$file"
fi
fi
dir="$1"
done
fi
}
dir=${1/~/$HOME}
if [ ! -d "$dir" ];then
dir="$PWD/$dir"
fi
search_folder $dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment