File Flags and the Finder
Removing invisible files
What .DS_Store, .localized, Icon and other invisible files on a Mac are, why they cause trouble on servers, Windows shares and in version control, how the Remove invisible files action deletes them in batches, and how to show invisible files in the Finder.
Typical usage scenarios
- preparing files for upload to a non-Mac system or a web server
- handing a folder to Windows users over a network share or on a USB stick
- cleaning a project folder before adding it to version control or an archive
- preparing files for a tool that does not know about macOS hidden files
The action
Select Remove invisible files in the Action: menu, drop the folders to clean into the file list and tick the kinds of file to remove:
Remove .DS_Store filesRemove "Icon" files (custom folder icons)Remove .localized filesRemove "._" AppleDouble files(the shadow files that macOS leaves next to every file on USB sticks, SD cards and SMB network volumes)Remove all other invisible UNIX files (names beginning with a ".")but keep version control and config files (.git, .gitignore, .env): ticked by default, this safeguard keeps.git,.svn,.hg,.bzr,.ssh,.gitignore,.gitattributes,.gitmodules,.gitkeep,.htaccess,.htpasswd,.envand.env.*,.editorconfig,.npmrc,.yarnrcand.nvmrcwhile everything else beginning with a dot is removedRemove all other files with the Finder's hidden flag
Tick Subfolders and their contents under Process: to clean the whole hierarchy. The action works on the folders in the file list: it looks inside them for the invisible files itself when you click Perform Changes, so the hidden files never appear in the list, and any plain files you dropped in are reported as ignored.
Removed files are moved to the Bin of the volume they are on, so a mistake can be recovered with the Finder’s Put Back until the Bin is emptied. The one exception is .DS_Store: macOS deletes these outright instead of moving them to the Bin. That is harmless, the Finder writes a fresh one the next time you open the folder.
When the action has finished, the summary tells you what went, for example “8 .DS_Store files, 1 .localized file, 1 Icon file, and 2 AppleDouble files moved to the Bin from 9 folders.” followed, when the broad option was on, by how many version control or config items were kept.
Read the precautions below before removing anything other than .DS_Store files.
What are invisible files?
Invisible files on macOS come in two different flavors: Unix-style invisible files and files with the Finder’s hidden flag (what Mac OS 9 called invisible files).
On Unix systems every file whose name starts with a full stop (e.g., .secret) is considered to be
invisible. Files with the hidden flag rely on a metadata flag that is part of the HFS+ and APFS
file systems; these files can have any name.
Invisible files are simply files that are not usually displayed by the Finder and in the various file dialogs; in all other respects they are perfectly “normal” files.
Invisible files exist because they usually contain “operating system stuff” that it is a bad idea for the user to mess around with.
Mac OS 9 used invisible files for a number of purposes, but the major one that still affects Macs today is its use of Icon\r files. These files contain the custom icon for the folder in which they are placed. In other words, whenever you see a folder that has a non-standard icon, chances are that there will be an invisible Icon\r file inside of it.
Unix systems make heavy use of invisible files for all kinds of purposes. A lot of configuration information is kept in invisible plain text files, such as .profile, .cshrc, etc. Removing these configuration files can have disastrous effects and may even prevent your system from re-booting properly.
Many third-party unix applications, such as version control systems (git, mercurial, subversion, cvs, etc.) use invisible folders and files to maintain state information.
The most commonly used hidden files on macOS are .DS_Store and .localized files.
Pretty much every folder on your hard disk is likely to contain a .DS_Store file. Its use by Apple is largely undocumented, but it is commonly believed to contain Finder-related information about the other files in the folder that contains it. This appears to include at least positioning information (the location at which the icon appears in the Finder’s as Icons view), what type of document each file represents, file comments, file color, etc. The main purpose of this file appears to be to boost the Finder’s performance when displaying the
folder contents to the user by acting as a “cache”.
The .localized files appear to simply contain user language dependent data. This allows the Finder to display localized folder (and file?) names. A good example of this is the Applications folder, which on the file system is called Applications, but magically appears to the user with a localized name (e.g. Anwendungen).
Why would I want to remove invisible files?
There are a number of reasons why you might want to get rid of some or all invisible files within a folder hierarchy:
- export files to a non-Macintosh system
- export files to another Macintosh system
- prevent multi-platform tools that are not aware of the Mac’s invisible files from “choking” on them
- save a little disk space
All those hidden files can cause mayhem when used in a context other than with a Mac-only application on your own Mac.
For one thing if they make their way onto a non-Macintosh system, they may no longer be hidden and all those
.DS_Store files will pollute your folder hierarchy. The Finder is prone to putting a .DS_Store file into
every directory that you look at, even if you only have a quick browse on a Windows NTFS volume. The
multi-platform CDs that you burn are also likely to have those files appear in them..
Worse than just polluting but not otherwise impairing non-Macintosh systems, invisible files may actually prevent
you from transferring files onto those systems in the first place. The so-called SMB remote file sharing with
Windows machines for instance is prone to “choking” on hidden Icon\r files in particular. After transferring
10GB of data over the connection, you’ll suddenly be presented with an error message “..\..\..\Icon could not
be found. Aborting.”
Many professional tools that have been migrated from other platforms (Unix, Windows, etc.) also simply do not know
about the Mac’s invisible files and this can produce all kinds of problems. Version control systems (such as
Subversion or CVS), for instance, will not ignore the hidden .DS_Store files and will consider that the folder
has changed each time those files are updated (potentially each time you point the Finder at them!). Once they
are under version control, they can cause further mayhem especially in multi-user environments.
As mentioned before, the .DS_Store files act as a cache for the Finder and if for any reason
(there appear to be plenty!) they get out of sync with the real contents of the folder, they can lead to stale
information about your files being displayed. Removing the .DS_Store file will force the Finder to update its
information (you will however lose file comments, colors, positioning, etc information if you do this!).
Precautions
It pays to be cautious when using this feature. We recommend that you:
- Make a backup of your folder hierarchy and remove the invisible files on the copy and not the original
- NEVER mess around with the hidden files in the system folder
- NEVER mess around with the hidden files at the root of your home folder
Stopping the Finder writing .DS_Store files to network and USB volumes
The Finder writes a .DS_Store file into every folder it displays, including folders on network shares and USB sticks, where Windows and Linux users see them as clutter. macOS has two settings that stop this for those kinds of volume; your own disk is not affected. Choose Stop the Finder writing .DS_Store files on network and USB volumes… in the Tools menu. The item shows a checkmark while the setting is active and choosing it again lets the Finder write the files once more. The setting takes effect the next time you log in. (This item is not available in the Mac App Store edition, File Multi Tool, because of App Store restrictions.)
Showing invisible files in the Finder
A Better Finder Attributes allows you to make all invisible files visible in the Finder. It does this by activating a “secret” Finder mode and without modifying any files, i.e. you needn’t worry about making irreversible changes to your file system simply by activating this mode.
Moreover, this functionality is not a “hack” that would make your Finder less stable, but it is a hidden feature developed by Apple engineers, presumably for their own convenience.
You can activate this mode by selecting Show invisible files in the Finder… in the Tools menu and later de-activate it using Hide invisible files in the Finder…. The Finder restarts each time, which closes its windows but changes nothing on disk. Note that since macOS Sierra the Finder keeps .DS_Store files hidden even in this mode; ._ files, .localized files and other names beginning with a dot do become visible. (This feature is not available in the Mac App Store edition, File Multi Tool, because of App Store restrictions.)