X

How to access hidden files to restore in Time Machine

If you need to restore hidden files using Time Machine you may run into some problems revealing them. Here are some methods for addressing this in OS X.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
4 min read

The filesystem in OS X is relatively clean by default when viewed through the Finder. The only folders you see are the system folder, applications folder, user home directories, and a few others that might be useful when configuring the system for your needs. In reality there are a number of hidden files and folders that help govern the behavior of OS X, and occasionally when configuring software packages you have to interact with these items.

Recently in the Apple Support Communities forum user "uwes98" had difficulties after uninstalling the technical computing application Matlab and removing the hidden "/etc" file at the root of the filesystem instead of the one Matlab had created in his home directory. This type of error is easy to make, especially if you are using the Terminal to remove files and inadvertently miss a simple character. For instance, take a look at these three commands (do not run them):

  1. sudo rm -rf ~/etc

  2. sudo rm -rf /etc

  3. sudo rm -rf ~ /etc

The first command would target and remove a folder "etc" within the current user's home directory, but the second and third commands would have devastating effects on the system. Without the tilde character (which specifies the path to the current user's home directory), the second command would remove the system's "/etc" folder that is at the root of the hard drive. This folder contains numerous configuration files for system services and removing it would essentially break much of the underlying structure of OS X.

The third command would have even greater consequences. The mistake here is to put a space between the tilde character and the rest of the command: this tells it to target all the files within the current user's home directory in addition to all the files in the system's "/etc" folder and remove them. As a result, not only would you break the system but you would delete all of your data. Not Good!

While these examples are a bit extreme, sometimes when people are configuring their systems "under the hood" they may corrupt a specific file or folder that they would like to restore. Luckily, Time Machine will back up all files on the system (hidden or not), so if you have that you can restore the files; however, you cannot do this directly at first, since Time Machine will not show hidden files.

Time Machine showing hidden files
With hidden files shown in the Finder, you can locate and remove these in Time Machine (click for larger view).

In some cases you can reveal the hidden files within a hidden directory by first going to that directory. In the case of ADC user "uwes98," if he had only removed one file from within the hidden /etc directory then he could have used the Finder's "Go to folder" command (in the Go menu) and typed "/etc" to go to the hidden folder. From here all the files in the /etc directory would be revealed and he could then have invoked Time Machine to locate the file of interest and restore a previous version of it.

Unfortunately, if you have removed a hidden directory that is within a normally visible directory (as is the case with the entire /etc directory), then the Finder will not allow you to see it by default, so using the "Go to folder" command will not work. Nevertheless you can still restore it using Time Machine by first showing hidden files in the Finder.

  1. Open the Terminal.

  2. Run the following command:

    defaults write com.apple.finder AppleShowAllFiles TRUE;killall Finder

  3. Go to the location of the missing hidden folder and invoke Time Machine to restore it.

  4. Run the following command to hide files:

    defaults write com.apple.finder AppleShowAllFiles FALSE;killall Finder

Finder preferences file in TextWrangler
If you cannot use the Terminal, locate these lines in the Finder preferences file and change FALSE to TRUE, then force-quit the Finder and hidden files should be revealed (click for larger view).

These commands will show the hidden files, but there is a caveat when dealing with a missing /etc folder and some other missing files in hidden folders, in that the Terminal may rely on them to function properly and therefore might not open or run commands if certain directories including the /etc directory are missing. There is a way around this if it happens, which is to manually adjust the Finder's preferences to show hidden files instead of using the Terminal procedure listed above.

To do this, go to the /uername/Library/Preferences/ folder and open the file "com.apple.finder.plist" in a program like TextWrangler (the program must be able to interpret binary property lists). With the file open, locate the key called AppleShowAllFiles, and under it you should see a string entry of FALSE. Change this to TRUE and save and close the file. Then press Option-Command-Escape to bring up the force-quit window and relaunch the Finder. Now all hidden files should be revealed, and you can invoke Time Machine to restore any missing hidden files to your system.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.