yf7yjq
Last Updated: February 25, 2016
·
4.286K
· amoniker
Avatar closeup

Clean up OSX .dotfiles

When using Finder, OSX generates some hidden files. These files are usually fine in the context of OSX, but may not be appropriate on remote servers, mounted drives, or in git repos.

They include .DS_Store and ._* files, as well as the .Trashes directory.

You could spend money on software like BlueHarvest to clean these files up automatically, or you could create a single alias that does it for free:

alias sweep="find . -name .DS_Store -type f -delete ; find . -type d | xargs dot_clean -m"

The first part (find . -name .DS_Store -type f -delete) will simply find all .DS_Store files (recursively) and delete them.

The second part (find . -type d | xargs dot_clean -m) uses an OSX builtin command called dot_clean which will clean up ._* files (which are called AppleDouble files and contain resource forks). dot_clean does not work recursively, so first we list all subdirectories underneath the current directory with find . -type d, then pipe the list to xargs which runs dot_clean -m on each item in the list.

If you'd also like to remove .Trashes directories, you could add one more command:

alias sweep="find . -name .DS_Store -type f -delete ; find -name .Trashes -type d -delete ; find . -type d | xargs dot_clean -m"

With .Trashes included, you might need to call the alias using sudo

Now, whenever you need to clean things up, just sweep!

Enjoy!

Say Thanks
Respond

1 Response
Add your response

23089
Cc1482b6867895fb0cc52063dc2b60e9

As a workaround for various scenarios (file list too long, whitespace in filename, relative path used) I found the following worked better for removing the ._* files:

find "$(pwd -P)" -type d -exec dot_clean -m "{}" \;
over 1 year ago ·
Filed Under