Numerous files, including many system files, are hidden from users and even administrators. This is by design. UNIX is configured to perform reliably, and by helping ensure critical files are free from inadvertent deletion, mistaken renaming, or accidental misplacement, many resources are hidden by default. Plus, hiding files users typically should not be touching or accessing helps create a more efficient OS, free of unnecessary clutter and errors.

These resources are hidden in two different ways. Files with a period as the first character of the filename are hidden both from viewing within Finder and when using the ls command within a terminal session. Alternatively, files can be hidden by setting their hidden flag. However, items hidden using the flag are still visible when performing ls commands; setting the hidden flag only hides items from Mac OS X Snow Leopard’s Finder.

How to hide items using the command line

In a seeming Catch-22, Mac OS X prevents users from creating filenames that begin with a period. Users, including administrators, first need to create the file normally. Then, once the file is created, the file can be hidden using the mv command.

For example, to hide a file named test.docx from the Snow Leopard desktop, administrators need only type mv desktop/test.docx .test.docx. The file is now hidden from both Finder and basic ls command searches.

How to reveal items using the command line

To reveal hidden files, from a command prompt, use the -a switch with the ls command. For example, administrators can type ls -a at a command prompt to reveal hidden files.

Note that, when Mac OS X Snow Leopard hides files, it may relocate the file accordingly, depending upon the location in which it was stored and the method being used to hide the file. For example, when restoring a file originally stored on the Desktop that was hidden by adding a period to the front of its filename, by typing mv .test.docx test.docx at a command prompt, the file is restored (as test.docx without the period) not to the user’s Desktop (the original location) but to the root of the user’s home directory.

Administrators wishing to hide files only from Finder can do so using the chflags command. Typing chflags hidden desktop/test.docx hides the file from Finder, while typing chflags nohidden desktop/test.docx unhides the file from Finder.

Working with hidden files

Keeping hidden files hidden is an administrator’s best defense when it comes to protecting critical system files or other resources from accidental access, edits, deletions or other changes. While it’s possible to always display hidden files-by typing defaults write AppleShowAllFiles YES at a command prompt-I don’t recommend using that method as it is a clearly novice operation pregnant with potential for trouble. Instead, selectively hiding and unhiding files using the steps described above will help ensure critical resources remain hidden.