Find and remove Mac OS X dotfiles

There are two types of hidden “dotfiles” that OS X clutters USB drives with:

.DS_Store and ._filename (for example ._catfish.jpg)

To find all these files in a folder (In example: /home/yourfolder ), run this:

find /home/folder -name ._* -o -name .DS_Store

To delete them instead of just displaying them, use this command:

find /home/folder -name "._*" -o -name ".DS_Store" | sed 's/.*/"&"/' | xargs rm

Note: The sed command is used to enclose all input sent to rm with quotes, so it works with files containing spaces.

Leave a Reply

Your email address will not be published. Required fields are marked *

Markdown is allowed in comments.