The macOS graphical user interface (GUI) is renowned for its elegance and user-friendliness, making even complex tasks seem effortless. But beneath this polished veneer lies a beast of raw power: the Terminal. For the uninitiated, the Terminal can appear daunting, a relic from a bygone era of computing. For power users, however, it’s a direct portal to the system’s core, offering unparalleled control, automation capabilities, and access to functionalities that the GUI simply doesn’t expose.
While many users dabble with basic commands like ls or cd, there’s a treasure trove of “secret” or less-known commands that can dramatically enhance your productivity, customize your system, troubleshoot issues, and unlock hidden features. These aren’t necessarily obscure, but rather commands whose true potential often goes unrecognized, residing just beneath the surface, waiting for a power user to harness them.
This article is your guide to navigating these deeper waters. We’ll dive into a curated selection of advanced Mac Terminal commands, explaining their purpose, demonstrating their syntax, and outlining practical scenarios where they can transform your workflow. Prepare to transcend the ordinary and command your Mac like never before.
Mastering System Aesthetics: Hidden UI Tweaks
The visual experience of macOS is often cited as a major draw, but even its polished interface can be further refined or customized to suit a power user’s specific tastes. The defaults write command is your key to unlocking many of these hidden UI preferences, allowing you to tweak elements that Apple doesn’t expose in System Settings.
Instant Dock Hiding & Faster Animations
The Dock’s auto-hide feature is useful, but the slight delay can feel sluggish. Similarly, Mission Control and Exposé animations, while visually pleasing, can interrupt a rapid workflow.
To eliminate the Dock’s auto-hide delay:
defaults write com.apple.dock autohide-delay -float 0; killall Dock
To revert to the default delay:
defaults delete com.apple.dock autohide-delay; killall Dock
To speed up Mission Control/Exposé animations:
defaults write com.apple.dock expose-animation-duration -float 0.1; killall Dock
Change 0.1 to 0.0 for instant, or a higher value (e.g., 0.5) for slower.
To revert:
defaults delete com.apple.dock expose-animation-duration; killall Dock
After executing these, the killall Dock command is crucial as it restarts the Dock process for changes to take effect.
Disabling Screenshot Shadows
When you take a screenshot of a window using Cmd + Shift + 4 then spacebar, macOS adds an aesthetically pleasing shadow. However, for precise image manipulation or professional documentation, this shadow can be an annoyance.
To disable window shadows in screenshots:
defaults write com.apple.screencapture disable-shadow -boolean TRUE; killall SystemUIServer
To re-enable:
defaults write com.apple.screencapture disable-shadow -boolean FALSE; killall SystemUIServer
The killall SystemUIServer command is needed to restart the user interface server and apply the change.
Showing All Hidden Files by Default
While Cmd + Shift + . (dot) toggles hidden files in Finder, power users often prefer them to be permanently visible, especially when navigating project directories or system folders.
To always show hidden files in Finder:
defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder
To hide them again:
defaults write com.apple.finder AppleShowAllFiles -bool false; killall Finder
Remember killall Finder to apply the changes. This is a classic power user trick that every developer or system administrator should know.
Advanced File & Directory Operations
The Finder is great for visual navigation, but the Terminal offers unparalleled speed and precision for file and directory management, especially when dealing with large numbers of files, complex renaming tasks, or navigating deeply nested structures.
Manipulating Images with sips
The sips (scriptable image processing system) command is a hidden gem for anyone working with images. It allows you to resize, rotate, flip, and convert image formats directly from the command line, making it perfect for batch processing.
To resize an image to 800 pixels wide (maintaining aspect ratio):
sips -z 800 600 image.jpg # This resizes to fit within 800x600, maintaining aspect ratio.
sips -Z 800 image.jpg # This resizes the longest side to 800 pixels.
To convert an image from JPG to PNG:
sips -s format png image.jpg --out image.png
You can apply these commands to multiple files using a loop or wildcard:
for f in *.jpg; do sips -s format png "$f" --out "${f%.jpg}.png"; done
This single command allows you to perform powerful image manipulations without opening any graphical applications.
Precise File Searching with mdfind
While find is a standard Unix command, macOS offers mdfind, which leverages the Spotlight index for incredibly fast and powerful file searches, including content within files.
To find all .txt files containing the word “project” in your home directory:
mdfind -onlyin ~/ "kMDItemDisplayName =='*.txt'&& kMDItemTextContent =='*project*'"
You can query various metadata attributes (e.g., kMDItemKind, kMDItemLastUsedDate). To see all metadata attributes for a file:
mdls filename.ext
mdfind is significantly faster than find for complex searches across large volumes of data on macOS, as it utilizes pre-indexed information.
Unlocking the Power of chflags
The chflags (change flags) command allows you to set or unset specific flags on files and folders, affecting their behavior and visibility. This is more powerful than simply toggling hidden files in Finder.
To truly hide a folder, making it invisible even when “Show hidden files” is enabled in Finder:
chflags hidden /path/to/folder
To make it visible again:
chflags nohidden /path/to/folder
This is particularly useful for sensitive data or configuration folders you don’t want accidentally modified or seen by casual users.
Network & Connectivity Diagnostics
For troubleshooting network issues, analyzing connections, or simply understanding your network environment, the Terminal provides an arsenal of commands far superior to any GUI tool.
Advanced Network Configuration with networksetup
The networksetup command allows you to configure network settings directly, bypassing System Settings. This is invaluable for scripting network changes, managing multiple network locations, or quickly switching DNS servers.
To list all network services:
networksetup -listallnetworkservices
To set Google DNS servers for your Wi-Fi connection (replace “Wi-Fi” with your actual service name):
sudo networksetup -setdnsservers "Wi-Fi" 8.8.8.8 8.8.4.4
To revert to DHCP-assigned DNS:
sudo networksetup -setdnsservers "Wi-Fi" empty
You can also manage IP addresses, proxy settings, and more, making networksetup a crucial tool for network administrators and power users.
Inspecting DNS with scutil
To quickly inspect your current DNS configuration and resolution order, scutil is a lightweight yet powerful tool.
To see the current DNS configuration:
scutil --dns
This provides detailed information about your resolver configuration, including nameservers, domain suffixes, and more. It’s an essential first step when diagnosing domain resolution issues.
Peeking into Open Connections with lsof
lsof (list open files) is a versatile Unix command that, on macOS, can also show you which processes have network connections open. This is incredibly useful for identifying rogue processes or understanding network activity.
To list all open TCP connections with their associated processes:
lsof -iTCP -sTCP:LISTEN
lsof -iTCP -sTCP:ESTABLISHED
To find out which application is using a specific port (e.g., port 80):
sudo lsof -i :80
This command is a lifesaver for debugging port conflicts or identifying processes consuming network resources.
System Management & Diagnostics
The Terminal offers granular control and insights into your Mac’s internal workings that are often inaccessible through the standard GUI tools. From monitoring logs to managing power settings, these commands empower you to understand and optimize your system at a deeper level.
Real-time System Log Monitoring with log stream
Modern macOS versions use a unified logging system. While Console.app provides a GUI, log stream in the Terminal offers a powerful, real-time view of system activity, perfect for debugging or monitoring specific events.
To view all logs in real-time:
log stream
To filter logs for a specific process (e.g., “Finder”):
log stream --predicate 'process =="Finder"'
To filter by type or subsystem:
log stream --predicate 'messageType == 16'
log stream --predicate 'subsystem =="com.apple.WindowServer"'
log stream is an indispensable tool for diagnosing system freezes, application crashes, or unexpected behavior, providing immediate feedback on what the system is doing.
Power Management with pmset
The pmset (power management settings) command allows you to view and modify various power-saving options that go beyond the simple sliders in System Settings. This is critical for optimizing battery life, preventing sleep during critical operations, or scheduling specific power events.
To view current power settings:
pmset -g # General power settings
pmset -g log # Detailed power activity log
To prevent your Mac from sleeping when the display is off (useful for servers or long-running tasks):
sudo pmset -a disablesleep 1
To re-enable sleep:
sudo pmset -a disablesleep 0
You can also schedule startup/shutdown events, configure wake-on-LAN settings, and more with pmset, offering a truly granular approach to power management.
Clearing Inactive Memory with purge
While macOS is generally excellent at memory management, sometimes clearing inactive memory can be beneficial, especially after closing memory-intensive applications or when experiencing sluggishness. The purge command forces the system to clear cached data, making more RAM available.
To clear inactive memory:
sudo purge
It’s important to note that purge isn’t a magical performance booster and should be used judiciously. macOS will naturally manage memory efficiently. However, in specific scenarios (e.g., before running a memory-intensive task after a long session), it can provide a quick refresh.
Security & Privacy Enhancements
For power users, control over security and privacy is paramount. The Terminal provides direct access to system security features, allowing for robust configurations and detailed inspections of your Mac’s defenses.
Firewall Configuration with defaults write (Advanced)
While macOS has a user-friendly firewall interface, enabling or disabling it via the Terminal offers scripting possibilities and direct control.
To enable the application firewall:
sudo defaults write /Library/Preferences/com.apple.alf ALFGloballfState -int 1
To disable:
sudo defaults write /Library/Preferences/com.apple.alf ALFGloballfState -int 0
To see its current status:
defaults read /Library/Preferences/com.apple.alf ALFGloballfState
This requires a sudo command because it’s a system-wide setting. Always exercise caution when modifying system-level security preferences.
Managing Keychains and Certificates with security
The security command-line tool interacts directly with macOS Keychains, allowing you to manage passwords, certificates, and encryption keys without the Keychain Access app. This is especially useful for automation, scripting, or forensic analysis.
To list all keychains:
security list-keychains
To find a generic password for a specific service (e.g., “MyService”):
security find-generic-password -s "MyService" -g
The -g flag displays the password in plain text, so use with extreme caution and only in secure environments.
To add a password to the login keychain:
security add-generic-password -a "MyAccount" -s "MyService" -w "MyPassword" ~/Library/Keychains/login.keychain-db
The security tool is incredibly powerful for complex security management tasks, especially in server environments or for developers working with certificates.
Productivity & Workflow Hacks
Beyond system administration and customization, the Terminal can directly impact your daily productivity, offering tools to streamline repetitive tasks, enhance clipboard functionality, and even automate simple spoken announcements.
Preventing Sleep with caffeinate
If you need your Mac to stay awake for a specific task (e.g., a long download, rendering, or backup) without constantly interacting with it, caffeinate is your friend.
To keep your Mac awake indefinitely:
caffeinate
Press Ctrl + C to stop.
To keep your Mac awake for a specific duration (e.g., 1 hour = 3600 seconds):
caffeinate -t 3600
To prevent system sleep but allow the display to sleep:
caffeinate -s
caffeinate is much simpler and more direct than fiddling with power settings or third-party apps for temporary sleep prevention.
Clipboard Interaction with pbcopy and pbpaste
These two commands allow you to interact directly with the macOS clipboard (pasteboard), enabling powerful scripting and command-line data transfer.
To copy the output of a command to the clipboard:
ls -l | pbcopy
Now, you can paste the ls -l output into any application using Cmd + V.
To paste the clipboard content into a file or another command:
pbpaste > myfile.txt
This allows for seamless integration between the Terminal and your GUI applications, making data transfer incredibly efficient.
Text-to-Speech with say
The say command utilizes macOS’s built-in text-to-speech engine, allowing your Mac to speak any given text. This can be fun, but also incredibly useful for audible notifications or reading out long texts while you do other things.
To have your Mac speak a phrase:
say "Hello, power user! Welcome to the Terminal."
You can also pipe text to say:
cat myfile.txt | say
Or use a different voice (e.g., “Alex” or “Samantha”):
say -v Alex "I am your personal assistant."
This command adds an auditory dimension to your command-line interactions, useful for alerts or hands-free information consumption.
Final Thoughts: Embrace the Command Line
The Mac Terminal is far more than just a historical artifact; it’s a dynamic, powerful, and deeply integrated part of macOS that, once mastered, fundamentally changes how you interact with your computer. The “secret” commands we’ve explored today are just a glimpse into its vast capabilities. From subtle UI tweaks to robust system diagnostics, network control, and security enhancements, the command line offers a level of precision and efficiency that the GUI simply cannot match.
Remember that with great power comes great responsibility. Many Terminal commands, especially those prefaced with sudo, can make significant changes to your system. Always understand what a command does before executing it, and if in doubt, back up your data.
As a power user, your journey into the Terminal is an ongoing one. Continue to explore, experiment, and learn new commands. Integrate them into your scripts, create aliases for frequently used complex commands, and customize your shell environment. By doing so, you’ll not only unlock the true potential of your Mac but also transform your own efficiency and mastery over your digital environment. The command line awaits – go forth and command!