Remove .DS_Store files from certain folders
I had never really thought about it until today, but I am constantly deleting those pesky .DS_Store files that finder loves put everywhere. Since I’m always in the terminal anyway its just become a habit to rm .DS_Store when i come accross them. Today I decided that this is like killing 1 rabbit while the other 6,000 keep mating – ie: theres no point in wasting energy on 1 when you can give a flame thrower to a robot and stop those little things.
So heres what i came up with:
find /folder-to-clean/ -name ".DS_Store" -exec rm '{}' \;
Of course you can do anything you want with the -exec part, the ‘{}’ is just where the found filename goes – this is usually for my dev root, so they are constantly in the way and i want them deleted.
Next step is to setup a simple cron-tab to run whenever or even create a bash function like:
clean_ds(){
find $1 -name ".DS_Store" -ok rm '{}' \;
}
The function about uses -ok instead of -exec so it will ask you before deleting every file which i could imagine as getting obnoxious. If you are comfortable enough to use it just swap out the -ok with -exec.
Hope that helps some other fustrated people out there.
(if there is an easier way – and i’m sure there is – i’d love to hear it)







Add Yours
YOU