The macOS graphical user interface (GUI) is renowned for its elegance, intuitiveness, and user-friendliness. For the vast majority of users, it provides everything they need to navigate their digital world. But beneath this polished veneer lies a beast of incredible power and flexibility: the Unix-based command line interface, accessible through the Terminal.
For the uninitiated, the Terminal can appear intimidating—a black window filled with cryptic text. However, for power users, developers, and system administrators, it’s a gateway to unparalleled control, automation, and customization. It allows you to perform tasks that are either impossible through the GUI, incredibly cumbersome, or simply much faster when executed directly.
This article is your guide to unlocking that hidden power. We’re not just talking about basic commands like ls or cd; we’re diving deeper into lesser-known, yet incredibly potent, “secret” Mac Terminal commands that can transform your workflow, enhance your system’s behavior, and give you a level of mastery over your Mac you didn’t know was possible. Whether you’re looking to fine-tune system animations, manage network settings with precision, or manipulate files in ways Finder can only dream of, prepare to unleash the beast within your macOS machine.
Remember, with great power comes great responsibility. While these commands are powerful, some can alter critical system settings. Always understand what a command does before executing it, and be cautious when using sudo (superuser do) as it grants elevated permissions. Let’s begin our journey into the heart of macOS.
1. Prevent Your Mac from Sleeping with caffeinate
Ever been in the middle of a long download, a large file transfer, or a presentation, only for your Mac to decide it’s nap time? The caffeinate command is your digital espresso shot, keeping your system awake and active without needing to tweak system preferences.
caffeinate
What it does: This command temporarily prevents your Mac from sleeping. By default, it runs until you quit the Terminal process (Ctrl+C). You can also specify a duration:
caffeinate -t 3600 # Keeps Mac awake for 3600 seconds (1 hour)
caffeinate -d # Prevents display from sleeping
caffeinate -i # Prevents system from idle sleeping
Why it’s useful: Ideal for long-running processes, media playback, or any scenario where you need your Mac to stay awake without constantly interacting with it. Forget fiddling with power settings; just caffeinate and go.
2. Clear Inactive Memory with sudo purge
While macOS is generally excellent at memory management, sometimes clearing out inactive memory can give your system a noticeable boost, especially after closing memory-intensive applications.
sudo purge
What it does: This command flushes the disk cache and inactive memory. purge doesn’t free up “used” memory; rather, it forces macOS to relinquish memory that was held by applications but is no longer actively being used (marked as “inactive”).
Why it’s useful: You might use this if your Mac feels sluggish and you suspect memory pressure, even if the Activity Monitor doesn’t show a lack of available RAM. It forces the system to re-evaluate what memory it truly needs, often resulting in a snappier response. Always check vm_stat before and after to see its effect.
Caution: While generally harmless, overuse isn’t necessary as macOS will manage memory on its own.
3. Advanced Image Manipulation with sips
The sips (scriptable image processing system) command is a hidden gem for anyone who works with images. It allows you to resize, rotate, flip, convert, and query image properties directly from the command line.
sips -z 600 800 image.jpg # Resize image to 600px height, 800px width
sips -s format png image.jpg --out image.png # Convert JPG to PNG
sips -f horizontal image.png # Flip image horizontally
sips -r 90 image.jpg # Rotate image 90 degrees clockwise
sips -g pixelWidth -g pixelHeight image.jpg # Get image dimensions
What it does: sips is a powerful tool for batch processing images or quickly performing single image modifications without opening a graphical editor.
Why it’s useful: Essential for web developers, designers, or anyone needing to quickly manipulate image files for consistency. Imagine resizing hundreds of photos for a website in seconds.
4. Toggle Hidden Files in Finder
macOS hides certain system files and dot files by default to prevent accidental modification and reduce clutter. Power users often need to access these files, and while a keyboard shortcut exists (Cmd + Shift + .), the Terminal offers a persistent toggle.
defaults write com.apple.Finder AppleShowAllFiles TRUE; killall Finder
What it does: This command writes a preference to Finder’s property list (.plist) to show all files, then restarts Finder to apply the change.
To revert:
defaults write com.apple.Finder AppleShowAllFiles FALSE; killall Finder
Why it’s useful: Indispensable for debugging, modifying configuration files, or simply exploring the full structure of your macOS system.
5. Instant Dock Auto-Hide/Show
If you use your Dock on auto-hide, you might find the slight delay before it appears or disappears a tiny bit irritating. This command removes that delay entirely.
defaults write com.apple.dock autohide-delay -float 0; killall Dock
What it does: Sets the auto-hide delay for the Dock to zero, making it appear and disappear instantly. The killall Dock command restarts the Dock process for the change to take effect immediately.
To revert to default delay (or set your own):
defaults delete com.apple.dock autohide-delay; killall Dock
# Or set a specific delay, e.g., 0.5 seconds:
# defaults write com.apple.dock autohide-delay -float 0.5; killall Dock
Why it’s useful: A minor tweak that provides a significant boost to the perceived responsiveness of your macOS interface for minimalists and efficiency enthusiasts.
6. Disable Gatekeeper (Use with Extreme Caution!)
Gatekeeper is a security feature that helps protect your Mac from malware by ensuring only trusted software runs. While it’s a vital defense, power users might occasionally need to temporarily disable its stricter controls for specific development or testing scenarios.
sudo spctl --master-disable
What it does: This command completely disables Gatekeeper, allowing applications from “Anywhere” to run without macOS checking their signatures. It adds an “Anywhere” option to System Settings > Privacy & Security > Security.
To re-enable Gatekeeper (highly recommended):
sudo spctl --master-enable
Why it’s useful: Primarily for developers or those needing to run unsigned, legacy, or self-compiled applications that Gatekeeper would otherwise block.
Extreme Caution: Disabling Gatekeeper significantly reduces your Mac’s security posture. Only do this if you understand the risks and are absolutely sure of the origin and safety of the software you are running. Re-enable it as soon as your task is complete.
7. Spotlight from the Terminal with mdfind
Spotlight is fantastic, but sometimes you want to leverage its powerful indexing capabilities directly from the command line, perhaps to integrate into scripts or filter results more precisely. Enter mdfind.
mdfind "keyword" # Search for files containing "keyword"
mdfind -name "image.jpg" # Find files named "image.jpg"
mdfind -onlyin ~/Documents "report" # Search for "report" only in Documents
mdfind "kMDItemKind =='PDF'" # Find all PDF files
What it does: mdfind uses the same metadata index as Spotlight, making searches incredibly fast. It supports advanced queries using kMDItem attributes.
Why it’s useful: Perfect for quickly locating files without leaving the Terminal, scripting complex file searches, or finding specific types of documents across your system.
8. Terminal to Clipboard with pbcopy and pbpaste
These two simple commands bridge the gap between your Terminal and the macOS clipboard, allowing you to seamlessly copy and paste text without relying on graphical selections.
cat file.txt | pbcopy # Copy the content of file.txt to the clipboard
pbpaste > newfile.txt # Paste clipboard content into newfile.txt
echo "Hello World" | pbcopy # Copy "Hello World" to clipboard
pbpaste # Print clipboard content to Terminal
What they do: pbcopy takes standard input and places it onto the clipboard. pbpaste prints the current clipboard content to standard output.
Why they’re useful: Incredibly handy for copying long strings, complex commands, file paths, or output from other commands directly to your clipboard for use elsewhere, and vice-versa.
9. Make Your Mac Talk with say
The say command is a fun and surprisingly useful utility that converts text into spoken audio using your Mac’s built-in text-to-speech engine.
say "Hello, power user! Welcome to the hidden world of macOS."
say -v Alex "I can speak in different voices."
say -o output.aiff "This will be saved to an audio file."
What it does: Reads out the provided text. You can specify different voices (say -v ? to list available voices) and even save the spoken output to an audio file (.aiff).
Why it’s useful: Great for accessibility, proofreading articles, getting audible alerts in scripts (e.g., “Your backup is complete!”), or just for a bit of fun.
10. Real-time System Logs with log stream
macOS, like any Unix-based system, generates vast amounts of log data. While Console.app provides a GUI for this, log stream offers a powerful, real-time view directly in the Terminal.
log stream
log stream --predicate 'process =="Finder"' # Stream logs only for Finder
log stream --predicate 'category =="Error"' # Stream only error messages
What it does: Displays system logs in real-time as they occur. You can filter logs using predicates based on process name, category, message content, and more.
Why it’s useful: An essential tool for troubleshooting system issues, debugging applications, or simply monitoring system activity as it happens. Far more agile for quick checks than opening the full Console app.
11. Flush DNS Cache with dscacheutil -flushcache
When you experience issues accessing certain websites or suspect DNS resolution problems, flushing your DNS cache is often the first troubleshooting step.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
What it does: Clears the macOS DNS resolver cache. The killall -HUP mDNSResponder command is also often included for older macOS versions or for a more comprehensive flush.
Why it’s useful: Helps resolve issues where your Mac is pointing to outdated or incorrect IP addresses for domain names, ensuring it fetches fresh DNS records.
12. Advanced Network Configuration with networksetup
The networksetup command offers a comprehensive way to query and configure network settings for all your network interfaces directly from the Terminal.
networksetup -listallhardwareports # List all network interfaces
networksetup -getairportpower en0 # Check Wi-Fi status (en0 is often Wi-Fi)
networksetup -setairportpower en0 off # Turn Wi-Fi off
networksetup -setairportpower en0 on # Turn Wi-Fi on
networksetup -setdnsservers "Wi-Fi" 8.8.8.8 8.8.4.4 # Set custom DNS for Wi-Fi
networksetup -setmanual "Wi-Fi" 192.168.1.100 255.255.255.0 192.168.1.1 # Manual IP
What it does: This versatile command allows you to inspect and modify virtually any network setting, from Wi-Fi power to IP addresses, DNS servers, and proxy settings.
Why it’s useful: Invaluable for network administrators, developers, or anyone who frequently switches network configurations or needs precise control over their Mac’s networking behavior, often for scripting network changes.
13. List Open Internet Files and Sockets with lsof -i
For understanding what processes are accessing the network, what ports are open, and what connections are established, lsof (list open files) is an incredibly powerful utility.
sudo lsof -i # List all open internet files and sockets
sudo lsof -i :80 # List processes using port 80
sudo lsof -i tcp:443 # List processes using TCP port 443
sudo lsof -i -P | grep LISTEN # List all listening ports (with port numbers)
What it does: lsof reports information about files opened by processes. The -i flag specifically filters for internet files (sockets).
Why it’s useful: A go-to command for network troubleshooting, identifying rogue processes, checking if a service is correctly listening on a port, or diagnosing connection issues.
14. Advanced File Copying with ditto
While cp is great for basic file copying, ditto is a more robust tool, especially when dealing with entire directories or needing to preserve specific file attributes.
ditto source_directory destination_directory # Copy directory preserving metadata
ditto -V source_directory destination_directory # Verbose copy
ditto -rsrcFork source.app destination.app # Preserve resource forks (important for some apps)
What it does: ditto copies files and directories. Its key advantage over cp -R is its ability to preserve resource forks and HFS+ metadata, which is crucial for some macOS-specific files and applications. It also handles symbolic links intelligently.
Why it’s useful: Ideal for creating perfect copies of applications, system components, or complex directory structures where cp might lose critical macOS-specific data. It’s often used for cloning bootable disks or creating archives.
15. The Power of Pipelines and xargs
xargs is not a “secret” command per se, but its ability to turn standard input into arguments for other commands makes it incredibly powerful and often underutilized by intermediate users. It’s how power users truly automate tasks.
find . -name "*.bak" | xargs rm # Find all .bak files and delete them
ls *.txt | xargs -I {} mv {} {}.old # Rename all .txt files to .txt.old
grep -l "old_string" * | xargs sed -i '''s/old_string/new_string/g' # Find and replace in files
What it does: xargs reads items from standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (supplied by arguments) one or more times with each item as an argument.
Why it’s useful: It’s the glue that connects different commands, allowing you to build complex, automated workflows where the output of one command becomes the input for another. Essential for batch processing, file management, and scripting.
16. Terminal Multiplexing with screen or tmux
While not single commands, screen and tmux are indispensable utilities for power users who spend significant time in the Terminal. They are terminal multiplexers.
screen # Start a new screen session
tmux # Start a new tmux session
What they do: These tools allow you to run multiple independent Terminal sessions within a single Terminal window. You can switch between them, detach from a session (leaving processes running in the background), and reattach later from another Terminal instance, or even another computer via SSH.
Why they’re useful: Crucial for developers running servers, compiling code, or performing long tasks without worrying about their SSH connection dropping or closing their laptop. They greatly enhance productivity and workflow management in the command line.
17. Show Full Path in Finder Title Bar
By default, Finder’s title bar shows only the current folder name. For power users who navigate complex directory structures, seeing the full path can be incredibly helpful.
defaults write com.apple.finder _FXShowPosixPathInTitle -bool TRUE; killall Finder
What it does: Modifies a Finder preference to display the full POSIX path in the title bar of Finder windows instead of just the folder name.
To revert:
defaults delete com.apple.finder _FXShowPosixPathInTitle; killall Finder
Why it’s useful: Provides immediate context for your location within the file system, reducing ambiguity and improving navigation efficiency, especially when working with similar folder names across different branches.
18. Open Files with Specific Applications
The open command can do more than just open a file with its default application. You can specify which application to use, even if it’s not the default.
open -a "Google Chrome" index.html # Open index.html with Chrome
open -a "Visual Studio Code" my_project/ # Open a folder in VS Code
open -a Preview document.pdf # Open document.pdf with Preview
What it does: The -a flag tells the open command to launch the specified application and then open the provided file(s) or directory with it.
Why it’s useful: Perfect for quickly opening a file in a non-default application without dragging and dropping, or for scripting workflows where you need to process a file with a particular tool.
Best Practices for Terminal Power Users
As you delve deeper into the Terminal, keep these best practices in mind to maximize your efficiency and minimize potential mishaps:
- Read
manpages: For any command you’re unsure about, typeman <command_name>(e.g.,man ditto) to access its manual page. This is the definitive guide to its options and usage. Pressqto quit the man page. - Start with
pwdandls: Always know your current working directory (pwd) and list its contents (ls) before executing commands, especially those that modify files. - Use
sudojudiciously:sudogrants superuser (root) privileges. This means you can modify or delete any file on your system, including critical system files. Always double-check commands before usingsudo. - Backup, backup, backup: Before making significant system-wide changes, especially those involving
defaults writeorspctl, ensure you have a recent backup of your system. Time Machine is your friend. - Test in a safe environment: If you’re experimenting with complex scripts or potentially destructive commands, consider testing them in a virtual machine or on a non-critical part of your system first.
- Aliases and Functions: For frequently used long commands or sequences, create aliases in your shell configuration file (e.g.,
~/.bash_profileor~/.zshrc). - Version Control: For configuration files and scripts, consider using a version control system like Git to track changes and easily revert if something goes wrong.
Conclusion
The macOS Terminal is an incredibly powerful environment, offering a level of control and flexibility that the graphical interface simply cannot match. By mastering these “secret” Mac Terminal commands, you move beyond being just a user and become a true power user—someone who can finely tune their system, automate tedious tasks, and troubleshoot issues with precision and speed.
From manipulating images and managing network settings to tweaking UI behaviors and gaining deeper insights into your system’s activity, the commands we’ve explored barely scratch the surface of what’s possible. Embrace the command line, continue to explore, and you’ll find an endless world of possibilities to customize and optimize your macOS experience. So, open your Terminal, type a command, and truly unleash the beast within your Mac. The power is now in your hands.