The graphical user interface (GUI) of macOS is renowned for its elegance and intuitive design. It’s a masterpiece of user-friendliness, guiding you through tasks with clicks and drag-and-drops. But beneath this polished veneer lies a powerful, often overlooked realm: the Terminal. For the uninitiated, it’s a daunting black window filled with cryptic text; for the seasoned power user, it’s a direct portal to the very core of macOS, offering unparalleled control, efficiency, and access to functionalities Apple never exposed in the GUI.
This article isn’t about the everyday ls or cd. We’re diving deep into the clandestine corners of macOS, unearthing “secret” Terminal commands that empower you to diagnose complex issues, customize your system beyond imagination, automate tedious tasks, and wield your Mac with the precision of a master craftsman. If you consider yourself a power user, eager to unlock every ounce of potential from your machine, then prepare to elevate your macOS experience to an entirely new level.
We’ll explore commands that grant you granular control over system processes, network configurations, file attributes, and even the subtle animations that define your daily interactions. Be warned: with great power comes great responsibility. While these commands are immensely useful, some can significantly alter system behavior. Always understand what a command does before executing it, and when in doubt, consult the man page (e.g., man pmset) or perform a quick online search. Let’s embark on this journey to transform your Mac from a user-friendly companion into a truly bespoke powerhouse.
1. The defaults Command: Your Gateway to Hidden UI Tweaks
Perhaps the most prolific “secret” command for customizing macOS is defaults. This command allows you to read, write, and delete preferences stored in .plist files, which define almost every aspect of your system’s behavior, from app settings to system animations. While some preferences are exposed in System Settings, countless others remain hidden, ripe for discovery by the adventurous power user.
Reveal Hidden Files in Finder
One of the most requested features by power users is the ability to easily toggle visibility for hidden files (those starting with a dot, like .DS_Store). The Finder usually keeps these out of sight.
defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder
To hide them again, simply change true to false. The killall Finder command restarts the Finder process, applying the changes immediately.
Customize Screenshot Format and Location
By default, macOS saves screenshots as PNGs to your Desktop. If you prefer JPEGs (smaller file size) or want them saved elsewhere, defaults has you covered.
# Change screenshot format to JPG
defaults write com.apple.screencapture type JPG; killall SystemUIServer
# To change back to PNG:
defaults write com.apple.screencapture type PNG; killall SystemUIServer
To change the default save location:
# Change screenshot save location to a "Screenshots" folder in your Documents
defaults write com.apple.screencapture location ~/Documents/Screenshots; killall SystemUIServer
Remember to create the Screenshots folder first if it doesn’t exist.
Speed Up/Slow Down Dock Autohide Animation
If you use the Dock in autohide mode, you might find the animation slightly slow. You can drastically speed it up or even remove the delay entirely.
# Remove autohide delay
defaults write com.apple.dock autohide-delay -float 0; killall Dock
# Speed up autohide animation
defaults write com.apple.dock autohide-time-modifier -float 0.4; killall Dock
Combine both for a near-instantaneous Dock experience. Adjust the -float value for autohide-time-modifier to fine-tune the animation speed. To revert to default, delete the preference:
defaults delete com.apple.dock autohide-delay; defaults delete com.apple.dock autohide-time-modifier; killall Dock
Disable Opening/Closing Window Animations
For those who prioritize speed over aesthetics, you can disable the smooth window animations.
defaults write NSGlobalDomain NSAutomaticWindowAnimationEnabled -bool false
To re-enable:
defaults write NSGlobalDomain NSAutomaticWindowAnimationEnabled -bool true
You might need to log out and back in or restart your Mac for this change to take full effect across all applications.
2. pmset: Mastering Your Mac’s Power Management
The pmset (power management settings) command is an indispensable tool for Mac laptop users and anyone concerned with their Mac’s energy consumption and sleep behavior. It gives you far more control and insight than the basic settings pane.
View Detailed Power Log and Thermal History
Ever wondered why your Mac woke up unexpectedly or what caused a battery drain?
pmset -g log # Displays a comprehensive power management log
pmset -g thermlog # Shows thermal state history (e.g., when fans spun up)
These logs provide invaluable diagnostic information, showing sleep/wake events, battery state changes, and even thermal throttling.
Schedule Automatic Wake/Sleep Events
You can schedule your Mac to wake up or sleep at specific times, perfect for nightly backups or automated tasks.
# Schedule Mac to wake up at 7:00 AM on weekdays
sudo pmset schedule wake "M T W Th F" 07:00:00
# Schedule Mac to sleep at 10:00 PM every day
sudo pmset schedule sleep "MTWTFSS" 22:00:00
Remember to use sudo for these commands as they modify system-level power settings. To list scheduled events, use pmset -g sched. To remove a scheduled event, use sudo pmset schedule cancel [type] (e.g., sudo pmset schedule cancel wake).
Prevent Sleep with caffeinate
If you need your Mac to stay awake for a specific task, like a long download or compilation, without changing your global sleep settings, caffeinate is your friend.
# Prevent system sleep (but display can still sleep)
caffeinate
# Prevent display sleep as well
caffeinate -d
# Prevent idle sleep, display sleep, and disk sleep
caffeinate -ids
# Run a command and keep the system awake only for its duration
caffeinate -u -t 3600 # Keep awake for 1 hour (3600 seconds)
The -u option asserts a user activity assertion, while -t sets a timeout. Just run caffeinate in a separate Terminal window, and it will keep your Mac awake until you hit Ctrl+C.
3. diskutil: Advanced Disk and Volume Management
The Disk Utility application is great for basic tasks, but diskutil in the Terminal provides granular control over disks, partitions, and volumes, including APFS snapshots.
List All Disks and Partitions
diskutil list
This command provides a detailed list of all physical and logical disks, partitions, and volumes, including hidden recovery partitions and system volumes, which are not visible in the GUI Disk Utility. It’s crucial for understanding your disk layout.
Mount a Volume Read-Only
Sometimes you need to inspect a volume without accidentally modifying it.
# First, find the identifier (e.g., disk2s1) using `diskutil list`
diskutil mount readOnly /dev/diskXsX
Replace diskXsX with the actual identifier of the volume you want to mount.
Manage APFS Snapshots
APFS snapshots are a powerful feature, often used by Time Machine. diskutil allows you to list and even delete them directly.
# List all APFS snapshots for the root volume
diskutil apfs listSnapshots /
This is particularly useful if you need to free up disk space by manually removing old snapshots that Time Machine hasn’t purged yet (use with caution!).
Verify and Repair Volumes
While Disk Utility has a “First Aid” feature, diskutil can sometimes provide more explicit control or feedback.
# Verify the integrity of the root volume
diskutil verifyVolume /
# Repair the root volume (requires booting into macOS Recovery)
diskutil repairVolume /
Running repairVolume on the boot volume requires booting into macOS Recovery mode (hold Command + R during startup).
4. mdfind: Spotlight’s Hidden Terminal Twin
Spotlight is incredibly powerful for finding files and information. mdfind brings that power to the Terminal, allowing for scripted searches and advanced queries that are difficult or impossible with the GUI.
Find Files by Type and Location
# Find all PDF documents within your Documents folder
mdfind "kind:pdf" -onlyin ~/Documents
# Find all files containing "report" in their name within your entire home directory
mdfind "report" -onlyin ~
# Find all applications that start with "Google"
mdfind "kMDItemKind =='Application'&& kMDItemDisplayName =='Google*'"
mdfind uses Spotlight’s metadata queries, allowing you to search by kind, name, content, date created, size, and many more attributes. Consult man mdfind for more query options. This is incredibly useful for finding specific file types or content across your entire drive, or within specific directories, much faster than a graphical search.
5. csrutil: System Integrity Protection (SIP)
System Integrity Protection (SIP) is a crucial security feature introduced in OS X El Capitan, designed to prevent malicious software from modifying protected files and folders on your Mac. While it’s generally ill-advised to disable SIP, power users and developers might need to temporarily do so for specific tasks, like debugging kernel extensions or modifying system files for development purposes.
Check SIP Status
csrutil status
This command will tell you whether SIP is enabled or disabled on your system.
Disabling/Enabling SIP (Advanced Users Only)
Warning: Disabling SIP significantly reduces your Mac’s security. Only do this if you fully understand the risks and have a specific, temporary need. You must boot into macOS Recovery mode (hold Command + R during startup) to change SIP status.
Once in Recovery mode, open Terminal from the Utilities menu and run:
# To disable SIP
csrutil disable
# To enable SIP
csrutil enable
After running the command, restart your Mac. Again, for most users, SIP should always remain enabled.
6. log stream: Real-time System Log Monitoring
macOS generates a vast amount of log data, which is invaluable for troubleshooting and understanding system behavior. The log stream command allows you to view these logs in real-time in your Terminal, filtering them as needed.
Monitor Logs for a Specific Process
# Stream logs related to the Finder process
log stream --predicate 'process =="Finder"'
# Stream error messages from Safari
log stream --style compact --predicate 'process =="Safari"&& messageType == error'
This is a powerful debugging tool. You can filter by process name, message type, subsystem, category, and more. The --style compact option makes the output less verbose.
7. lsof: Listing Open Files and Network Connections
lsof (list open files) is a versatile Unix command that lists information about files opened by processes. In macOS, it’s particularly useful for seeing what files a process is using, and crucially, what network connections are active.
Find Processes Using a Specific Port
# See what process is listening on port 8080
sudo lsof -i :8080
# List all TCP listening ports and the processes behind them
sudo lsof -iTCP -sTCP:LISTEN
This is invaluable for developers or anyone trying to troubleshoot network conflicts (e.g., “port already in use”).
See All Open Files for a Specific Application
# Find the PID of an application (e.g., Safari)
pgrep Safari
# Then, list all files opened by that PID
sudo lsof -p [PID_OF_SAFARI]
This can help diagnose issues where an application is holding onto files or resources.
8. scutil: Deep Dive into Network Configuration
While networksetup provides many network configuration options, scutil (System Configuration Utility) offers even lower-level access to macOS’s network services database.
Query DNS Server Settings and Hostname
# View the currently configured DNS servers
scutil --dns
# Get the local hostname
scutil --get HostName
scutil --dns can be particularly useful for diagnosing DNS resolution issues, showing you which servers are being queried and their order.
Modify Local Hostname (Advanced)
# Set a new local hostname (requires sudo)
sudo scutil --set HostName "my-new-mac-name"
This changes the name your Mac uses on the local network (distinct from the computer name in System Settings).
9. tmutil: Time Machine Control from the Terminal
Time Machine is macOS’s built-in backup solution. tmutil provides command-line control over its functions, allowing for more advanced management than the GUI.
List Local Snapshots
tmutil listlocalsnapshots /
This shows the local backups stored on your boot drive, which are part of Time Machine’s strategy for protecting your data even when your backup drive isn’t connected. These can sometimes consume significant space.
Start a Time Machine Backup
tmutil startbackup
Useful for scripting backups or initiating one immediately without opening System Settings.
Compare Backup Content
tmutil compare /Volumes/TimeMachineBackup/Backups.backupdb/YourMacName/Latest
This command allows you to compare the current state of your system with a specific Time Machine backup, showing differences. Replace the path with your actual Time Machine volume and latest backup path.
10. security: Interacting with macOS Security Services
The security command-line tool provides a powerful interface for interacting with macOS’s Keychain, certificates, and encryption services. This is invaluable for developers, system administrators, and anyone managing cryptographic assets.
Find Passwords in Keychain
Warning: Be extremely cautious with this command as it can expose your stored passwords. Only use it on your own machine and with full awareness of who might be watching your screen.
# Find generic password for a service
security find-generic-password -s "YourServiceName" -g
Replace "YourServiceName" with the name of the service (e.g., “Google Chrome”, “Adobe ID”) as it appears in Keychain Access. The -g flag reveals the password; without it, it just confirms existence.
Verify a Certificate
# Verify the validity of a certificate file
security verify-cert -c /path/to/your/certificate.pem
This is useful for checking the integrity and trust chain of SSL/TLS certificates.
11. chflags: Changing File Flags for Advanced Control
The chflags (change flags) command allows you to modify special attributes (flags) on files and folders, affecting how the system treats them. These flags are not accessible through the Finder’s Get Info panel.
Hide a File from the Finder
While the defaults write command toggles all hidden files, you can hide individual files using chflags.
chflags hidden /path/to/your/secret_document.txt
The file will disappear from Finder but remains accessible via Terminal or open -a Finder . from the parent directory. To unhide: chflags nohidden /path/to/your/secret_document.txt.
Make a File Immutable (User-Level)
The uchg (user immutable) flag prevents a file from being modified, deleted, or renamed, even by its owner. This provides a strong level of protection for critical files.
chflags uchg /path/to/my_important_document.doc
To unlock: chflags nouchg /path/to/my_important_document.doc. Note that root can bypass uchg with sudo. For even stronger protection, there’s schg (system immutable), but only root can set/unset it, and it often requires disabling SIP.
12. networksetup: Configure Network Services
networksetup provides command-line control over your Mac’s network interfaces and configurations, mirroring and expanding upon System Settings’ Network pane.
List All Network Services
networksetup -listallnetworkservices
This command shows all recognized network interfaces (e.g., Wi-Fi, Ethernet, Bluetooth DUN) by their service names.
Set DNS Servers for a Service
# Set Google Public DNS for the "Wi-Fi" service
sudo networksetup -setdnsservers "Wi-Fi" 8.8.8.8 8.8.4.4
Replace "Wi-Fi" with the name of your desired network service from listallnetworkservices. To remove custom DNS and use DHCP: sudo networksetup -setdnsservers "Wi-Fi" empty.
Get MAC Address of an Interface
networksetup -getmacaddress "Wi-Fi"
Useful for network troubleshooting or for setting up MAC address filtering on routers.
13. say: Your Mac Can Talk!
A fun and surprisingly useful command for scripting or quick notifications, say leverages macOS’s text-to-speech capabilities.
Make Your Mac Speak
say "Hello, power user! Welcome to the hidden world of macOS."
You can pipe output from other commands to say for audible alerts.
# Get current time and have your Mac say it
date | say
# Have your Mac speak with a specific voice (e.g., "Victoria", "Alex")
say -v "Victoria" "The quick brown fox jumps over the lazy dog."
To list available voices: say -v '?'.
The Power User’s Philosophy: Explore, Learn, Automate
These “secret” Terminal commands are just the tip of the iceberg. The true power lies not just in knowing individual commands, but in understanding how they interact, how to combine them into powerful scripts, and how to troubleshoot when things go awry.
Key takeaways for the aspiring macOS power user:
- Read the
manpages: Almost every command has a manual page (man [command_name]) that details its options and usage. This is your primary source of truth. - Start small, test often: When experimenting with new commands, especially those involving
sudoordefaults write, try them on non-critical files or settings first. - Backup, backup, backup: Before making significant system changes, ensure you have a recent Time Machine backup or clone.
- Embrace Homebrew: While not a “secret” command, Homebrew is the de facto package manager for macOS and allows you to install countless Unix utilities and tools that further extend your Terminal’s capabilities.
- Learn Shell Scripting: Combining these commands into
.shscripts allows you to automate complex workflows and truly unleash your Mac’s potential. - Customize Your Shell: Enhance your Terminal experience with custom prompts, aliases, and functions by modifying your shell’s configuration file (
~/.zshrcfor Zsh,~/.bash_profilefor Bash).
The macOS Terminal is more than just a developer’s tool; it’s an extension of your will, offering a level of control and efficiency that no GUI can match. By mastering these hidden commands, you’re not just performing tasks; you’re transforming your interaction with your Mac, moving from a mere user to a true maestro of your machine. So, open that black window, and start exploring the depths of macOS – your Mac will thank you for it.