What is the defaults Terminal command in macOS?

Some tips for macOS involve opening a Terminal window and typing an obscure command starting ‘defaults write blah blah…’ Have you ever wondered what it all means? Here is the answer.

In this article I will take a look at the defaults Terminal command and see what it is and how it works. As an example, I will show how to reveal hidden files that are stored on your iMac’s or MacBook’s drive. There are easier ways to do this, but it is a simple tweak that demonstrates how the defaults command works.

The macOS X defaults Terminal command is a tool that is used to view and modify the settings used by macOS X and applications. These settings are stored in .plist files, most of them anyway.

Many apps have a Preferences menu and the options you set in the Preferences are stored in .plist files. However, not all of the settings in plist files are available in an app's Preferences and there are sometimes hidden secret settings. These can be useful and they can be accessed through the defaults command.

In Finder, pull down the Go menu then hold down the Option key and click Library. Open the Preferences folder in Library and you will see a large number of files ending .plist. One them is called com.apple.finder.plist and this stores the settings for Finder.

View plist file contents

If you want to see what settings are stored in com.apple.finder.plist the easiest way is to just press the spacebar to open it in Quick Look.

I have highlighted a key called AppleShowAllFiles and the string that follows it, FALSE. We will see how to change these shortly.

View plist files in Terminal

Go to the Utilities folder and then run Terminal.app. At the command prompt in the Terminal window, type:

defaults read com.apple.finder

When viewing plist files you must omit the .plist at the end of the filename because defaults assumes it’s a .plist file. Defaults displays a lot of information and you will need to use the vertical scroll bar on the right side of the Terminal window to view it all. Scroll back to the top as in this screenshot:

Notice the line that says AppleShowAllFiles = FALSE near the top. The way the defaults command shows the plist file is actually more readable than Quick Look. It is the same information, just displayed differently.

This is a simple setting in Finder and some of the other settings are much more complicated, so let’s focus on this one.

Show plist file values with defaults

Suppose we wanted to find out the value of just this one setting, AppleShowAllFiles, without the page after page of code we had before. In this case we would enter:

defaults read com.apple.finder AppleShowAllFiles

Defaults reads the com.apple.finder.plist file, searches for AppleShowAllFiles and outputs its value, which is FALSE.

One of the functions of the defaults command is to read the value of a setting in a .plist file. In this case com.apple.finder.plist but it could be any of the plist files in Library > Preferences.

Change plist file values with defaults

Suppose we wanted to change the value of this setting. Instead of defaults read we would use defaults write and supply it with the new value:

defaults write com.apple.finder AppleShowAllFiles TRUE

Defaults opens com.apple.finder.plist, searches for AppleShowAllFiles and sets the value to TRUE. This particular setting has values of TRUE or FALSE, but other settings can contain numbers or text strings.

Here is how a Finder window looks when AppleShowAllFile is set to FALSE:

It does not show all files and some are hidden, although you may never have realised this. When AppleShowAllFile is set to TRUE and a Finder window is opened, it looks like this:

Notice that there are a lot more folders and files and that some are displayed in light gray. They are hidden ones (starting a file or folder name with a dot will hide it).

If you try this command and do not immediately see the hidden items, either log out and log back in to force Finder to read its preferences file again, or go to the Apple menu, select Force Quit, select Finder and click Relaunch. Finder restarts and reads its preferences in the plist file.

To stop showing hidden files, just use defaults again like this:

defaults write com.apple.finder AppleShowAllFiles FALSE

Take care with defaults

Some of the settings in plist files are important to macOS or applications and a wrong value could cause problems, so don't change anything unless you know what values are acceptable.

If you would like some more Terminal command tips, take a look at How to customise the power settings from Terminal and How to update macOS and apps from the Terminal command line.

Affiliate link

Recommended Mac software: CleanMyMac X
Use this multifunction tool to clean junk from the Mac, optimize it, run maintenance scripts, uninstall apps and left-overs and more. Use the realtime protection and a malware scanner to block malware. Click for more info