See All Previously Used Defaults Commands?
In this article
Yes, you can see all previously used defaults commands on macOS by checking your shell history (if you ran them in Terminal) or by reviewing system logs for changes made via the defaults command. The most direct way is to search your shell history file, but there is no built-in macOS feature that lists every defaults command ever executed.
What the defaults Command Does
The defaults command in macOS reads and writes user preference settings stored in property list (plist) files. These files live in ~/Library/Preferences (for user-level settings) and /Library/Preferences (for system-wide settings). When you run a command like defaults write com.apple.finder AppleShowAllFiles -bool true, it modifies the plist file for that domain. The command is commonly used to tweak hidden settings that aren't exposed in System Settings, such as showing hidden files, changing screenshot formats, or adjusting trackpad behavior.
How to Find Previously Used Defaults Commands
Because defaults commands are typically typed into Terminal, your shell history is the first place to look. Here are the methods:
- Check shell history: If you use bash, run
history | grep defaults. For zsh (the default shell since macOS Catalina), usehistory | grep defaultsorfc -l | grep defaults. This shows commands from your current session and previous ones if history persistence is enabled. - Search the history file: If you haven't restarted Terminal, the commands are in memory. After restart, they're saved to
~/.bash_history(bash) or~/.zsh_history(zsh). You can open these files in a text editor or usegrep defaults ~/.zsh_history. - Use the
defaultscommand itself: Rundefaults readto see the current state of all preferences. This won't show the commands, but it reveals what changes were made. For a specific domain, usedefaults read com.apple.finder. - Check system logs: macOS logs some
defaultsactivity to~/Library/Logsor the unified log. Uselog show --predicate 'process == "defaults"' --last 1hto see recent executions (requires admin rights for some entries).
Why You Might Want to See Them
There are several practical reasons to review past defaults commands:
- Undo a change: If you set a preference and later want to revert it, you need the exact command to delete or reset the key.
- Replicate settings on another Mac: If you're setting up a new machine, having a list of your tweaks saves time.
- Troubleshoot: If a setting isn't working as expected, seeing the exact command you used helps identify typos or wrong domains.
- Learn: Reviewing your own commands can help you understand what you've changed and why.
Common Problems and Limitations
There are a few reasons you might not find what you're looking for:
- History not persisted: If you close Terminal without saving history (or if history is disabled), commands are lost. You can enable persistent history in zsh by adding
setopt HISTFILE=~/.zsh_historyandsetopt SAVEHIST=1000to your.zshrc. - Commands run by scripts: If a script or app ran
defaults, it won't appear in your interactive shell history. - Logs may be truncated: The unified log only retains a certain amount of data, and not all
defaultscalls are logged with full arguments. - Multiple users: Other user accounts on the Mac have their own history files, so you won't see their commands unless you have access.
How to See Current Defaults Values
If your goal is to see what settings are currently in effect (rather than the commands), you can read the plist files directly. Run defaults read to dump all user preferences, or specify a domain: defaults read com.apple.dock. You can also browse the plist files in ~/Library/Preferences using the PlistBuddy tool or a property list editor. For example, to see the value of a specific key, use defaults read com.apple.finder AppleShowAllFiles. This is often more useful than trying to reconstruct commands from history.
Alternatives to the Defaults Command
While defaults is the standard tool, there are alternatives:
- PlistBuddy: A lower-level tool that can read and write plist files directly. Example:
/usr/libexec/PlistBuddy -c "Print :AppleShowAllFiles" ~/Library/Preferences/com.apple.finder.plist. - Graphical apps: Apps like TinkerTool or OnyX provide a GUI for many common defaults tweaks, and they often log what they change.
- Configuration profiles: For managed environments, you can use
profilesto set preferences, and those are visible in System Settings > Privacy & Security > Profiles.
Frequently Asked Questions
Can I see all defaults commands ever run on my Mac?
No, there is no complete log of every defaults command. Shell history only captures commands you typed in Terminal, and even that may be incomplete if history isn't saved. System logs may capture some activity, but they're not exhaustive and may not include the full command line.
How do I undo a defaults command if I don't remember the exact syntax?
You can delete the specific key using defaults delete domain key. For example, if you changed com.apple.finder AppleShowAllFiles, run defaults delete com.apple.finder AppleShowAllFiles. This removes the key, reverting to the default behavior. If you don't know the key, read the domain with defaults read com.apple.finder to see all keys and values.
Why doesn't my shell history show defaults commands?
Your shell might not be saving history, or the commands were run in a script or another app. Check if your .zshrc or .bashrc sets HISTFILE and SAVEHIST. Also, if you use multiple Terminal tabs, each has its own history buffer until saved. Run history to see the current session's commands.
Is there a way to log all defaults commands automatically?
You can add a wrapper function to your shell that logs each defaults command. For example, in zsh, add a function like defaults() { echo "$(date): $*" >> ~/defaults_log.txt; command defaults "$@"; } to your .zshrc. This logs every call you make in Terminal, but not those from other apps.
Can I see defaults changes made by apps?
Yes, you can check the current values with defaults read, but you won't see the commands. To see when a plist was last modified, use ls -l ~/Library/Preferences/com.apple.finder.plist. Some apps also write to their own logs, but there's no universal way to trace which app made a change.
What if I reset my Mac? Are defaults commands recoverable?
No, if you erase your disk or restore from a backup that doesn't include your shell history, the commands are gone. However, you can export your history before resetting by copying ~/.zsh_history to an external drive. Alternatively, you can back up the entire ~/Library/Preferences folder to preserve the current settings.