Tip: Quickly back up OS X system files and settings before tweaking
You can use the Finder's Paste Exactly feature to make quick, restorable backups of system files you might be adjusting when troubleshooting or tweaking OS X.
OS X ships with a default configuration and set of settings adjustment options that should work for most people's needs; however, there are times when you might wish to adjust a hidden setting or two, or troubleshoot problems by adjusting settings, databases, caches, and other files that are buried in various system folders. There are numerous online resources that can help, but even if you are comfortable exploring these files, it's good to have a way of reversing any changes you make.
Granted, OS X includes the Time Machine backup service thatby default, and as such is a good first line of defense. Time Machine should make it possible to restore any file or folder accessible through the Finder, regardless of special attributes like permissions and ownership settings. However, there can sometimes be problems, for example, files being in use or an I/O error with the Time Machine drive that results in a read/write error when restoring.
You can maintain multiple backup programs to overcome this, but another approach is to manually create a backup of the files you are editing or removing so you can restore them from it if necessary. In OS X Lion, Apple introduced an option in the Finder to copy and paste files while retaining their original file attributes, meaning that if a file is owned by the root user account and you do not have access to it, you can still copy the file as is. To do this, select the file or folder and press Command-C to copy it (or choose "Copy" from the Edit menu). Then go to another location on your drive (the Desktop or your home folder) and press Shift-Option-Command-V (or choose "Paste Exactly" from the Edit menu while holding the Shift and Option keys).
When this action is performed, the system will ask for your administrative account password, then run the copy process as the root user and secure an exact copy of the files. This ensures that after making edits and system modifications, you can quickly access this copied file and restore it by likewise pasting it exactly back where you got it from.
This approach is useful if you would like to remove a file or folder of interest (even if you do have default read access to it) to see how the system behaves without it. However, this is only relevant if you know what file or folder you are targeting in your troubleshooting efforts. When troubleshooting OS X a common recommendation is to make changes using the "defaults" command, which accesses the preferences files for various applications and background services, and is often used to tweak OS X settings. For example, the following defaults command will allow the Finder to reveal many hidden files:
defaults write com.apple.finder AppleShowAllFiles true
This command makes changes to a settings file for the Finder in the user's home folder, and while this file can be accessed directly, its location is not indicated directly by the "defaults" command. In addition, other uses of the command may target system files or hidden settings files that are harder to reveal and manage through the Finder.
Since the "defaults write" command is so commonly recommended, one way to back up the current setting being adjusted is to first use the defaults command to read the targeted setting so you have a record of what it is before making any changes to it.
To do this, you just need to make two changes to most defaults commands out there on the Internet. The first is to change the word "write" to "read," so that instead of making changes, it reads the settings. The second change is to remove the last word in the command, which when using "defaults write" is the new value being used for the setting ("true" or "false", or some new integer value) and is not needed to simply read a current settings value. Taking the above command as an example, one could read its current setting before making any changes by modifying it to look like the following:
defaults read com.apple.finder AppleShowAllFiles
With the information from reading the current setting in this manner, you can then make your changes using "defaults write" and be confident you can revert the new value back to the old one. In some cases when reading a setting's value you may get an output that reads, "The defaults pair could not be found." This indicates the setting being tweaked is an internal one that does not exist by default in the program's preference file. In these cases, if you tweak this setting by using "defaults write" then it will be added to the respective program's preferences file, so to revert the setting you will need to delete it, which can be done by rerunning the command and substituting the word "delete" for either "read" or "write."
defaults delete com.apple.finder AppleShowAllFiles