Last Updated: February 25, 2016
·
813
· maikel22

remove all .DS_Store pollution

Also irritated by those unusefull .DS_Store's?

Install this open source app that prevents creating them:
http://asepsis.binaryage.com

Because it will only prevent future .DS_Store creatures, I wrote a script to delete the existing ones:

#!/bin/bash

# This script removes all annoying .DS_Store's recursively from you Mac
# The first argument is the starting directory

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