If you are a Mac OS X user, you will probably be familiar with the “.DS_Store” file that the system automatically creates when you open a folder. What the “.DS_Store” file does is store custom attributes of the folder, such as the position of icons or the choice of a background image, so that the next time you open the same folder it will remain in the same state as the previous session.
The “.DS_Store” file is hidden by default, and most of the time it doesn’t cause any trouble – that is until you need to zip the folder and send it to your friends (using another operating system) or upload your development folder to the server. You will find that the folder contains many unsightly “DS_Store” files that you don’t want to share with you friends.
If you are looking for a way to quickly remove all instances of “.DS_Store” file in a folder, here is a command that you can use:
Note: the following command will work in Linux as well.
1. Open a terminal in your Mac OS X.
2. Enter the following command:
find /path/to-folder \( -name '.DS_Store' \) -delete
Replace the “/path/to/folder” with the actual filepath of the folder, for example “/var/www/html.”
What the above command does is use the
find command to search a particular folder (recursively) for files with a name that includes “.DS_Store” and delete them when found.
That’s it. You can now easily remove all instances of “.DS_Store” files before you share the folder with others.