Tutorial: Now you see 'em, now you don't: Invisible files in Mac OS X
Tutorial: Now you see 'em, now you don't: Invisible files in Mac OS X
Originally posted Wednesday, May 19th
by Ted Landau
Even though you can't see them, invisible files are critical to the operation of your Mac. For example, Apple typically makes certain files invisible to reduce the chance that the files are unintentionally deleted or edited. One of the most well known examples of these transparent creatures are the old Classic Mac OS Desktop database files; these are the ones that get rebuilt when you "rebuild the desktop" in OS 9.
Mac OS X expands the use of invisible files far beyond anything attempted by the Classic OS. There are more invisible files in Mac OS X, more ways to make files invisible, and more ways to get in and out of trouble by accessing these files.
In this tutorial article, we'll examine the methods OS X uses to makes files invisible, what and where the major invisible files are, how you can change an item's invisibility status, and how knowing all of this can help in troubleshooting.
- This tutorial by MacFixIt Contributing Editor Ted Landau was originally published on MacFixIt as a three-part series. Ted has substantially revised it for Panther compatibility, based on his new Mac OS X troubleshooting book, Mac OS X Help Line.
In order for a file to be invisible in OS X, it does not have to drink a magic elixir. But it does have to meet one of the three criteria that the Finder checks in determining a file's status. The following sections describe these criteria; along the way, we also describe how to get any and all invisible files to appear on your desktop.
1. The invisible bit
Every file or folder on your Mac has a set of attributes (or "bits") that determine characteristics of the item. One such attribute is the invisible bit. When this bit is enabled, the item is invisible in the Finder. When the bit is off, the item can be seen. This method is essentially the same one used to make files invisible in OS 9. Thus, a file with its invisible bit set will be invisible in both OS 9 and OS X.
How to toggle the invisible bit A default installation of Mac OS X does not provide a way to toggle the invisible bit on and off. So, if you want to do this, you'll need some additional help. There are basically two ways to go here:
- Use utilities. An assortment of third party utilities provide the means to toggle the invisible bit.
- XRay. Drag any file or folder icon to the XRay application's icon and an XRay Info window for the item opens. One of the options in the window is a check box to enable the file's invisible attribute. If you enable this option, and save the changes, the selected file is now... still plainly visible. What's up? The Finder does not respond to the change until you relaunch the Finder (or log out and log back in).
To relaunch the Finder, choose Force Quit from the Apple menu and select Finder in the resulting Force Quit Applications window. Then click the Relaunch button. The Finder will quit and relaunch and the file will vanish!
Figure 1: XRay's invisibility option
Simple enough. Okay, now let's go in the reverse direction. Begin again by dragging the file's icon to the XRay icon and... oops. The file is invisible -- there's no icon to drag. Don't fret. There are several ways to resolve this inevitable dilemma of invisible files.
For starters, you can still use XRay. If you just recently made the file invisible, you can use the hierarchical menu accessed from XRay's Open Recent command (it's in the File menu). The file you want will be listed there; just select it and it opens in XRay even though you can't see it in the Finder.
If the item is too "old" to still be in the Open Recent menu, use XRay's Open Quickly command instead (it's also in the File menu). From the text box that appears, type the absolute path of the item you want to open. For example, if an invisible file called MyDoc is on your OS X Desktop, enter ~/Desktop/MyDoc in the text box to load the file in XRay. [Note: ~ is the symbol for the root level of the Home directory of the currently logged-in user.]
If you don't know the pathway to the file -- or maybe you are even unsure of the exact name of the file -- there is still hope. The solution is to either: (1) use a utility to create a list of all invisible files, find the one you want and open it; or (2) make all invisible files temporarily visible and locate the file from the Finder itself.
- Lists: File Buddy and the Finder's Find. If the "list" solution appeals to you, File Buddy is the utility you want. In its Cleaning menu is an item called "Find Invisible Items." Select it. From the window that appears, select the drive(s) you want to search, click the Search button and wait for your list to appear.
Figure 2: File Buddy's "Find Invisible Items" window
Note: Before clicking the Search button, enable the Ignore options (at least the first two). This causes File Buddy to ignore invisible files that recur repeatedly on a typical OS X volume and (unless you are specifically looking for one of these files) otherwise cause the list to become annoyingly long. For example, it generally pays to ignore the directory store (.DS_Store) files. They pop up in virtually every folder you access. Mac OS X uses them to store the data needed to remember the location of icons in icon view for that folder.
Once you have a list of results, File Buddy includes its own option to toggle a file's invisible bit, so there is no need to return to XRay to do this. Just click on the file's name in the list and select Get Info (Command-I); a window will open that includes the invisible bit setting in the "Finder Flags" column on the right-hand side.
Alternatively, to just see a list of invisible items -- perhaps to determine the location of a specific item or to open an invisible text file in a text editor -- you can use the Finder's Find command. Just select "Visibility" from the criteria pop-up menu and "invisible items" from the pop-up menu that appears to the right. However, Find does not list items in the /System directory unless you specifically choose to search that folder.
Finder: InVisibles To make all invisible files visible in the Finder, use a utility such as InVisibles. To use InVisibles, just launch it and click the Visible button: this relaunches the Finder with all formerly invisible items now visible.
Figure 3: InVisible's window
You can now drag the desired no-longer-invisible file to XRay and change its status. After having done so, go back to InVisibles and click the InVisible button. All normally invisible files will vanish, but the file that you modified will not.
Finder: Property List Editor What utilities such as InVisibles are really doing is toggling a setting in the Finder's preferences file. The utility performs -- in a user-friendly way -- something that you could also do in other less-friendly ways without the need for third-party software. The Finder's preferences file is called com.apple.finder.plist and is located in ~/Library/Preferences. While this file can be opened and edited via almost any text editor, I prefer to use an Apple utility designed specifically to work with plist (property list) files. It's called Property List Editor and it is included as part of the Developer Xcode Tools software. It opens preferences (.plist) files in a formatted layout that makes it easy to scan and edit the content.
Note: The Developer Xcode Tools software comes with retail purchases of Mac OS X. An installer for the software is also pre-installed on all new Macs. You can also download it for free from here (after first obtaining a free membership in Apple Developer connection [ADC], as described on the page).
Once you've installed the Xcode Tools software, you'll find Property List Editor in the /Developer/Applications/Utilities folder. Launch it and open com.apple.finder.plist. You can now make the same change directly that you otherwise do indirectly with InVisibles. Here's how:
- Click the disclosure triangle to the left of the word Root to reveal the list of properties.
- Locate the property called AppleShowAllFiles.
- In the Value column, click the word No and hold down the mouse button.
- When the pop-up menu appears, choose Yes.
- Save and close the document.
- Relaunch the Finder.
To make invisible files invisible again, just reverse the change. There is no advantage to using Property List Editor here over InVisibles. The general advantage of Property List Editor is that it provides access to all the available options in a plist file, not just the one(s) that a utility allows you to modify. Using Terminal. If you are at least a bit familiar with Unix and prefer to use Terminal to accomplish this toggling of invisibility status, you can easily do so. One advantage of using Terminal is that files that are otherwise invisible in the Finder can be easily listed in Terminal.
For starters, you can accomplish the same changes just described with Property List Editor by using the defaults command. Specifically, to make invisible files visible, type the following: defaults write com.apple.finder AppleShowAllFiles Yes.
To toggle the invisibility bit of a single file, however, you?ll again need help from Apple's Xcode Tools software. This time you need a Unix program called SetFile. You'll find it, together with a collection of other Unix software, in the /Developer/Tools directory.
By default, the software in the Tools directory will not run simply by typing the name of the program (there are many ways to resolve this inconvenience, but that's a subject for another article). Here's the quickest and easiest way to put SetFile in action and use it modify a file's invisibility status:
- Launch Terminal.
- Open the /Developer/Tools folder in the Finder. Locate SetFile and drag its icon to the terminal window. The Directory path for SetFile (/Developer/Tools/SetFile) should appear in the Unix command line prompt.
- Type: -a V . Leave a space after the upper case V.
- Locate the file that you want to make invisible. Drag its icon to the Terminal window. Its path should now be added to the same command line prompt.
Thus, for our aforementioned MyDoc file on the Desktop, when you are done doing all of the above, the command line should look like this:
/Developer/Tools/SetFile -a V /Users/homedirectoryname/Desktop/MyDoc
where homedirectoryname is the name of your home directory (mine is landau, for example).
Figure 4: The SetFile command line prompt to turn on MyDoc's invisible bit
Now, press Return. This immediately enables the invisibility bit -- although, just as when doing this with XRay, the file will not actually turn invisible until the Finder is relaunched.
To reverse directions with SetFile, you do almost the same thing with two exceptions:
- Use a lower case v instead of an upper case V. This disables the invisible bit.
- Since you can't drag an invisible file's icon to the Terminal window, you'll need to know the file's path. If you haven't moved it from its prior location, the path is the same as the one that you used when you made the file invisible. Just retype it.
Although all of this works fine for turning a file's invisible bit on and off, you'll soon discover that there are files that are invisible even though this bit is off for those files. This is because, rather than limiting itself to this OS 9 legacy method for making a file invisible, OS X can use two other methods. In fact, it prefers these methods, as the vast majority of OS X invisible files use them.
2. The dot prefix
The most common method that OS X uses to determine if a file or folder should be invisible is to check if there is a period (dot) as the first character of the item's name. If the dot is there, the item is invisible. Mac OS X borrowed this method from Unix, which employs the same convention for its invisible files. Many preferences-related files in OS X, for example, are kept invisible via this method (as I will explore more later in this article).
Despite their invisibility, you can make these files appear on your desktop. You can even remove the period from their name so that they remain "permanently" visible. However, be wary of making this change with files used by OS X, as the OS may no longer recognize the file afterwards and may not take kindly to finding the needed file "missing." Instead, make a copy of the file and delete the period from the name of the copy.
The other advantage of making these files visible is that you can more easily edit their contents. As most of these files are plain text files, editing is as easy as opening the file in a text editor.
Unfortunately, adding or deleting a period at the front of a file's name is not quite as easy as it sounds. For one thing, the Finder prohibits you from adding a period here. If you try, you will get the following error message:
Figure 5: The Finder just says no
Conversely, you cannot easily remove the period from in front of the name of file that you cannot see. What to do?
- Use InVisibles, etc. Once again, a utility such as InVisibles is a simple and direct solution. Just run it and click its Visible button and all invisible files in OS X become visible. With invisible files visible, the Finder does allow you to add a period to the name of the file (and vice versa, of course).
Note: Diverting briefly, here's one example of how this technique can solve a minor crisis: Suppose you use an FTP client to download a file that starts with a period from a Unix server to your Desktop. Oops. The downloaded file is invisible on your Mac, even though the server copy was listed and easily accessible via the FTP client. After running InVisibles, the file can now be seen; you can now edit the file and upload the revised copy as desired.
Use BBEdit (or TextWrangler or BBEdit Lite). BBEdit (and its cousins) offers you the ability to edit any invisible text file without having to make the file visible first! This can be even faster than using InVisibles if all you want to do is change a line of text in the file. To do this, do the following:
- Launch BBEdit.
- Select "Open Hidden" from its File menu.
- From the window that appears, locate the invisible file and open it.
Modify the file and Save it.
You can even use Save As to create a duplicate file without the period prefix, so the copy remains visible.
One problem you may have with making changes to files as just described will occur if you do not have write permission for the file you want to edit. This is likely to be the case for files that are owned by root and are in the /System/Library directory, for example. In most cases, you probably shouldn't be messing with these files anyway. But if you are sure this is what you want to do, there are numerous solutions. If you are using BBEdit, it includes the option to save changes to such files after entering your administrator's password. End of problem. If you are using a text editor such as TextEdit, a solution is to use the Pseudo utility. To do so, drag the text editor application's icon to the Pseudo icon so as to open the application with root user access; you'll need to provide an admin-level username and password. You can now edit any file, no matter who owns it.
Use Terminal. If all you want to do is add or delete period prefixes for files, Terminal is probably the quickest and most efficient way to do so. This is because Terminal easily lists all invisible files and (unlike the Finder) permits the addition of a period prefix to a file. Here's and example of how it works:
- Launch Terminal.
- Type ls and press Return. This will give you a list of all the visible items at the root level of your Home directory. You don't really have to do this step. I just included it as a point of comparison with the next step
Type ls -a and press Return. This will give you a list of all the visible and invisible items at the root level of your Home directory.
To use this procedure to list invisible files in other locations, follow the ls command with the path to the location you wish to see. For example, to see all files, visible and invisible, on your Desktop, type:
ls -a ~/Desktop and press Return.
To add a period prefix to any file listed there (such as the MyDoc file mentioned earlier), type the following (and press Return):
mv ~/Desktop/MyDoc ~/Desktop/.MyDoc
This replaces the MyDoc file with a copy called .MyDoc.
Figure 6: Starting with .CFUserTextEncoding, the initial files in this list show the (.) invisible files located on at the root level of your home directory
The newly-named file (.MyDoc) is instantly invisible in the Finder. Unlike with the invisibility attribute change, there is no need to relaunch the Finder for the change to take effect. You can use the same method in reverse to remove a leading period from an file's name and make an invisible file visible.
3. The .hidden file
A file named .hidden is located at the root level of the OS X startup volume. Because of the dot at the start of its name, it is an invisible file. However, it is a special example of an invisible file. The contents of this text file is a list of other files and folders. The Finder makes every item in this .hidden list invisible -- regardless of whether or not the item's name starts with a dot/period. Most of the items listed here are BSD/Unix directories (such as etc and tmp) that provide the Unix basis for OS X. They are thus located at the same root level of the volume where .hidden itself resides. By their inclusion in this .hidden list, the items are kept invisible in the Finder. (Which is just as well -- otherwise, their presence would likely intimidate novice Mac users as well as open the door to undesired tampering with their contents.)
You can view the contents of the .hidden file via BBEdit or TextWrangler, using the same Open Hidden command mentioned earlier in this article. To do so, just navigate to the root level of your OS X volume and select the .hidden item.
Figure 7: The contents of the .hidden file, viewed in BBEdit
Alternatively, if you are comfortable using Terminal, you can view the contents in a variety of ways. One simple method is to type: cat /.hidden.
Although it is possible to modify what files are visible or invisible by editing the contents of this .hidden file, I would recommend against doing this. The .hidden file is OS X system software. It is invisible precisely to inhibit users from modifying its contents.
More to the point, most of the items listed in the .hidden list are folders/directoies. While the folder itself is invisible, the contents of the folder typically are not. To see (and possibly modify) the contents of an invisible folder, you have numerous options. One solution is to use a utility such as InVisibles to make all invisible items (including the folders listed in the .hidden file) temporarily visible. Another solution is to use Terminal (such as the aforementioned ls -a command to list invisible files and folders).
Alternatively, if you know the invisible folder's path, you can select the Go to Folder command (Command-Shift-G) from the Finder's Go menu. Enter the path in the text box that appears and click the Go button. This opens the folder's window where the (presumably non-invisible) contents will be revealed. Thus, to go to the invisible etc folder/directory, enter: /etc. (If you don't know the path, you'll either need to know a bit of Unix to determine its path via Terminal [a subject for another day] or revert to using InVisibles instead.)
SOLVING PROBLEMS WITH INVISIBLE FILES IN OS X
With the above techniques under your belt, you should now be able to locate any invisible file on your drive, change its invisibility status, and edit or move/delete the item if needed. All that's left is to provide a practical example of how using this stuff can help you troubleshoot your Mac. Here goes:
Global preferences settings problems
The .GlobalPreferences.plist files contain various settings that are "global" to your account or to the system in general. There are three such files in Mac OS X 10.3. The first one is in ~/Library/Preferences (that is, your Home directory); the second one is in /Library/Preferences; and the third one (and the one least likely to need to be modified or deleted) is in ~/Library/Preferences/ByHost (this one has letters and numbers added to its name that are derived from your Mac?s Ethernet/MAC address).
Each file contains different settings. The one in your Home directory Library folder contains your AppleID, your iTools member name, your alert (beep) sound, and more. The one in the root-level Library folder contains some of your Energy Saver settings, time zone settings, and more.
If problems occur with items related to these settings, you can simply delete the relevant file and log out. A new default copy will be present when you log back in. Hopefully, this will fix the symptoms. The obstacle here is that, as these files are invisible, you will have to do some extra work to locate the file so as to delete it. Here are two suggestions for what to do (using the file in the ~/Library/Preferences folder as the example):
Use InVisibles. Use InVisibles to make invisible files visible. Next, go to the ~/Library/Preferences folder and locate the file named .GlobalPreferences.plist. Delete the file. Finally, reverse the change you made with InVisibles.
Use Terminal. Launch Terminal and type:
Press Return and the file is deleted.
We've only scratched the surface of all the invisible items on your drive and how to use them. Invisible files (or files in invisible folders) play a role in maintaining the information listed in Printer Setup Utility. They are critical to networking, sharing and firewall configurations. The Finder uses them to carry out several of its functions, from remembering icon positions to storing files in the Trash. If you are motivated to learn more about these topics, check out MacFixIt's Archives and/or Apple's Knowledge Base. It's all there.
But no hurry. You now already know quite a bit about how all of this invisibility stuff works. You now qualify as a Mac OS X magician, capable of making files vanish and reappear at will. And you don't even need a magic wand.
Like what you've found in this tutorial? Get more troubleshooting guidance (updated daily) by subscribing to MacFixIt Pro.Resources