The graphical user interface (GUI) of macOS is renowned for its elegance, intuitiveness, and user-friendliness. For the vast majority of users, interacting with their Mac through clicks, drags, and menus is more than sufficient. But beneath this polished veneer lies a beast of raw power and granular control: the Terminal. For power users, the command line is not merely a relic of a bygone era; it’s a direct conduit to the macOS kernel, a secret language that unlocks hidden features, optimizes performance, and provides an unparalleled level of customization and control that simply isn’t available through standard system preferences.
If you’ve ever felt that your Mac, as amazing as it is, could do more, or if you’ve wanted to tweak a setting that Apple “forgot” to include in System Settings, then you’re precisely the audience for this deep dive. We’re about to explore a curated collection of “secret” Mac Terminal commands that will transform your interaction with macOS, turning you from a mere user into a true digital architect of your machine. These aren’t just obscure tricks; they are powerful tools that can streamline your workflow, enhance your privacy, provide deeper system insights, and truly unleash your Mac’s full potential. Get ready to tap into the hidden capabilities that make macOS one of the most powerful and flexible operating systems for those willing to venture beyond the GUI.
A Crucial Disclaimer Before You Begin
Before we dive into the fascinating world of Terminal commands, a word of caution is paramount. The Terminal grants you direct access to your system’s core. With great power comes great responsibility. Many commands, especially those prefixed with sudo (which stands for “superuser do”), will execute with administrative privileges, meaning they can modify system files, change core settings, or even delete critical data without asking for further confirmation once you’ve entered your password.
- Always Understand What You’re Doing: Never copy and paste a command into the Terminal if you don’t fully understand its function. A typo or a misunderstanding can lead to unintended consequences, data loss, or system instability.
- Back Up Your Data: Before making significant system changes, especially involving
sudocommands, it is always a good practice to back up your Mac using Time Machine or another reliable backup solution. - Start Small: Begin with less impactful commands and gradually work your way up as your comfort and understanding grow.
- The Internet is Your Friend: If in doubt, search for the command and its various options online to understand its full implications.
With that important warning out of the way, let’s don our power user hats and explore the hidden depths of macOS!
Unearthing Hidden macOS Functionality
macOS is packed with features that Apple deems too niche or too advanced for the average user to access via the GUI. The Terminal, however, provides a direct path to these capabilities, allowing you to fine-tune your Mac experience in ways you never thought possible.
Show All Hidden Files in Finder
By default, macOS hides certain system files and folders to prevent accidental deletion or modification. While this is generally a good safety measure, power users often need to see and interact with these files for troubleshooting, development, or advanced customization.
defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder
This command modifies the Finder preferences to display all hidden files (those starting with a dot, like .bash_profile or .DS_Store). The killall Finder part restarts the Finder application, applying the changes immediately. To revert this, simply change TRUE to FALSE.
Customize Screenshot Behavior
Taking screenshots on a Mac is easy, but by default, they include a shadow around windows. If you’re creating documentation or web content, a clean screenshot without shadows can be more professional.
defaults write com.apple.screencapture disable-shadow -bool TRUE; killall SystemUIServer
This command disables the automatic shadow around window screenshots. killall SystemUIServer restarts the system UI server to apply the change. To re-enable shadows, change TRUE to FALSE.
Display Full POSIX Path in Finder Window Title
For developers or those who frequently navigate deep directory structures, seeing the full path of the current folder in the Finder window title bar can be incredibly useful, saving you clicks and time.
defaults write com.apple.finder _FXShowPosixPathInTitle -bool TRUE; killall Finder
This command changes the Finder’s default behavior to show the complete file path in the title bar, similar to what you might see in a Terminal prompt. Revert by changing TRUE to FALSE.
Instant Dock Hiding and Showing
The macOS Dock is a fundamental part of the UI, but it can take up screen space. While it autohides, there’s a slight delay before it retracts or reappears. For maximum screen real estate and snappy responsiveness, you can eliminate this delay entirely.
defaults write com.apple.dock autohide-delay -float 0; killall Dock
This command sets the delay for the Dock’s autohide feature to zero, making it appear and disappear instantly when your cursor approaches the screen edge. To restore the default delay (or set a custom one), you can change -float 0 to a different value (e.g., -float 0.5 for half a second) or remove the specific preference.
Show Indicators for Hidden Applications in the Dock
When you hide an application, its icon typically disappears from the Dock. This command adds a subtle, translucent indicator underneath the icon of hidden applications, allowing you to quickly see which apps are running but not currently visible without switching through them.
defaults write com.apple.dock showhidden -bool TRUE; killall Dock
This small visual cue can enhance your multitasking workflow, especially if you frequently hide applications to de-clutter your desktop. To revert, change TRUE to FALSE.
Supercharging Performance & System Control
Beyond visual tweaks, the Terminal offers powerful commands to optimize your Mac’s performance, manage background processes, and gain deeper insights into its operational state.
Flush Your DNS Cache
Your Mac maintains a cache of DNS (Domain Name System) lookups to speed up website loading. However, if a DNS entry changes (e.g., a website moves to a new server), your Mac might continue trying to access the old address, leading to connectivity issues. Flushing the cache forces your Mac to request fresh DNS information.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
This two-part command clears both parts of macOS’s DNS cache. You’ll need to enter your administrator password for this sudo command. It’s a common first step in troubleshooting network connectivity or website access issues.
Prevent Your Mac from Sleeping on Demand
Sometimes you need your Mac to stay awake for an extended period, perhaps during a large download, a lengthy compilation, or when monitoring a process, without constantly fiddling with power settings. The caffeinate command is your friend.
caffeinate
Simply running caffeinate will prevent your Mac from sleeping until you press Control + C in the Terminal window, or close the window itself. You can also specify a duration in seconds: caffeinate -t 3600 will keep it awake for one hour. This is far more convenient than adjusting System Settings.
Enable Verbose Boot Mode
When your Mac starts up, you typically see the Apple logo and a progress bar. Verbose boot mode replaces this with a stream of text messages, showing every step of the boot process. This can be invaluable for diagnosing startup issues or simply understanding what happens behind the scenes.
sudo nvram boot-args="-v"
After running this command, restart your Mac. You’ll see the verbose output instead of the Apple logo. To revert, run sudo nvram -d boot-args and restart.
Manually Run Periodic Maintenance Scripts
macOS usually runs a set of maintenance scripts (daily, weekly, monthly) automatically in the background, typically when your Mac is awake but idle. However, if your Mac is often shut down or asleep, these scripts might not run as frequently as intended. You can manually trigger them.
sudo periodic daily weekly monthly
This command forces the execution of all three sets of periodic scripts. These scripts perform tasks like cleaning up log files, rotating system logs, and updating various system caches, which can help keep your system tidy and responsive.
Disable the Dashboard or Widgets
While the Dashboard (or Widgets in newer macOS versions) offered a quick glance at information, many power users find it an underutilized feature that consumes system resources. If you never use it, you can disable it entirely.
defaults write com.apple.dashboard mcx-disabled -boolean YES; killall Dock
This command completely disables the Dashboard/Widgets feature. If you ever wish to bring it back, change YES to NO and run the command again.
Mastering Advanced File Management & Privacy
The Terminal excels at file manipulation, allowing you to perform tasks that are cumbersome or impossible with Finder alone. It also provides fine-grained control over privacy settings.
Securely Delete Files and Folders
When you delete files through the Finder, they typically go to the Trash and can be recovered. Even after emptying the Trash, the data often remains on your disk until it’s overwritten. The srm (secure remove) command overwrites the data multiple times, making recovery extremely difficult or impossible.
srm -rf /path/to/your/sensitive/file_or_folder
WARNING: This command is irreversible. Once you use srm, the data is gone forever. Double-check your path rigorously before pressing Enter. Using -r for recursive (for folders) and -f for force (without confirmation). Exercise extreme caution.
Find Files with mdfind (Spotlight from the Command Line)
Spotlight is a powerful search tool, and mdfind brings that power directly to the Terminal. It searches the Spotlight index, making it incredibly fast.
mdfind "keyword"
mdfind -onlyin ~/Documents "report"
You can search for keywords, file types, or specific attributes. For example, mdfind -name "invoice.pdf" will find all files named “invoice.pdf” indexed by Spotlight. It’s much faster and more flexible than find for general content searches if Spotlight is properly indexed.
Copy Files with ditto (Preserving Attributes)
While cp is the standard copy command, ditto is more powerful, especially for copying entire directories and preserving extended attributes, resource forks, and permissions – crucial for maintaining file integrity, particularly with application bundles or system files.
ditto -V /source/path /destination/path
The -V flag provides verbose output, showing you what’s being copied. ditto is excellent for creating exact duplicates of folders or migrating user data.
List Detailed Disk Information
Understanding your disk layout and partitions is fundamental for system administration. diskutil provides comprehensive information about all mounted and unmounted drives.
diskutil list
This command will output a detailed list of all physical and logical volumes, their identifiers, sizes, and formats. It’s invaluable when troubleshooting disk issues, preparing to reformat drives, or understanding your storage configuration.
Reset Privacy Permissions for Applications
macOS has robust privacy controls, requiring apps to ask for permission to access your camera, microphone, contacts, photos, etc. Sometimes, an app might bug out, or you might want to revoke and re-grant permissions. tccutil lets you reset these permissions from the Terminal.
tccutil reset Camera
tccutil reset All
You can specify a service (e.g., Camera, Microphone, Contacts, Photos, Accessibility, ScreenCapture) or use All to reset all permissions. The app will then prompt you again for permission the next time it tries to access that service.
Remove Quarantine Attributes from Files
When you download a file from the internet, macOS often tags it with a “quarantine” attribute, prompting you for confirmation before opening it. While a security feature, it can sometimes be a nuisance for trusted files or developer tools.
xattr -cr /path/to/your/file_or_folder
The xattr command manages extended attributes. -c removes all attributes, and -r applies it recursively to a folder’s contents. This command is often used by developers to allow unsigned applications or scripts to run without constant security prompts. Use with caution, as it bypasses a security check.
Network Diagnostics & Security Insights
The Terminal offers a suite of networking tools that provide deeper insights than GUI utilities and allow for more advanced diagnostics and configuration.
Check Your Network Quality (macOS Monterey+)
For users on macOS Monterey or later, the networkQuality command provides a robust assessment of your network’s capacity, including upload and download speeds, responsiveness, and reliability.
networkQuality
This command runs a comprehensive test, providing metrics beyond simple speed tests, which can be invaluable for diagnosing streaming issues, video conferencing performance, or general network bottlenecks.
Detailed Network Interface Information
The ifconfig command (interface configuration) provides detailed information about all your network interfaces (Ethernet, Wi-Fi, Bluetooth, VPN tunnels, etc.), including IP addresses, MAC addresses, and packet statistics.
ifconfig
This is a fundamental command for network troubleshooting, allowing you to verify IP assignments, check interface status, and monitor network traffic at a low level.
View Network Routing Table
The netstat -nr command displays your Mac’s network routing table, which dictates how your computer sends and receives data across different networks.
netstat -nr
This output shows your default gateway, network destinations, and the specific network interfaces used for various routes. It’s a key tool for understanding your network configuration and diagnosing routing problems, especially in complex network environments or with VPNs.
Check System Integrity Protection (SIP) Status
System Integrity Protection (SIP) is a crucial security feature introduced in OS X El Capitan, designed to protect sensitive system files and processes from modification, even by a root user. Power users sometimes need to disable it (e.g., for specific kernel extensions or deep system modifications), but it’s vital to know its status.
csrutil status
This command will tell you if SIP is enabled or disabled. SIP can only be enabled or disabled from macOS Recovery Mode.
Disable Gatekeeper for Unsigned Apps (Extreme Caution!)
Gatekeeper is a macOS security feature that prevents apps not downloaded from the App Store or identified developers from running without explicit permission. While generally a good security measure, developers or power users testing unsigned software might temporarily need to bypass it.
sudo spctl --master-disable
EXTREME WARNING: Disabling Gatekeeper significantly reduces your Mac’s security posture and makes it vulnerable to malware. Only do this if you fully understand the risks and for a very specific, temporary purpose. Re-enable it as soon as possible with sudo spctl --master-enable.
Developer Tools & Productivity Boosters
For developers, system administrators, and anyone who wants to push their Mac’s capabilities, the Terminal is an indispensable environment for managing tools, automating tasks, and enhancing productivity.
Install Homebrew – The Missing Package Manager for macOS
Homebrew is arguably the most essential Terminal command for any Mac power user or developer. It’s a package manager that simplifies the installation of thousands of open-source tools, utilities, and applications that aren’t natively part of macOS.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After installing Homebrew, you can easily install software like git, wget, node, python, php, and countless other utilities with simple commands like brew install [package_name]. It transforms your Mac into a much more powerful development and administration workstation.
Use screen or tmux for Terminal Multiplexing
If you frequently work with multiple Terminal sessions, SSH into remote servers, or need to keep processes running even if your network connection drops, screen or tmux are indispensable. They allow you to create multiple virtual Terminal windows within a single Terminal session.
screen
# or
tmux
Once inside screen or tmux, you can detach from your session (e.g., Control + A, then D for screen) and reattach later, even from a different physical location, and your processes will continue running in the background. This is a game-changer for long-running tasks or remote administration.
Make Your Mac Speak Text with say
The say command utilizes macOS’s built-in text-to-speech engine, allowing your Mac to literally speak any text you provide. It’s not just a novelty; it can be integrated into scripts for audible notifications or to read out long texts hands-free.
say "Hello, power user! Welcome to the secret world of Mac Terminal commands."
You can customize the voice, speed, and even save the output as an audio file.
View Your Command History
Every command you type into the Terminal is typically saved in a history file (e.g., .bash_history or .zsh_history). This allows you to recall past commands, preventing repetitive typing and serving as a record of your Terminal activities.
history
This command will list your recent commands with their history numbers. You can then execute a specific command from history using ![number] (e.g., !123). You can also use Control + R to search your history incrementally.
Stream Real-time System Logs
macOS generates vast amounts of log data, recording everything from application events to system errors. While Console.app provides a GUI for viewing logs, the log stream command gives you a real-time, unfiltered view directly in the Terminal.
log stream
This command is invaluable for diagnosing issues as they happen. You can filter the output using options like --predicate to narrow down the log entries to specific processes or types of events.
Best Practices and Staying Safe
- Aliases: For frequently used long commands, create aliases in your shell configuration file (e.g.,
.zshrcor.bash_profile). For example,alias showhidden='defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder' - Know Your Shell: macOS uses Zsh by default now, but older systems used Bash. Commands might behave slightly differently, and your configuration files will vary (
.zshrcvs..bash_profile). - Man Pages: For any command you’re unsure about, type
man [command_name](e.g.,man srm) to access its manual page, which details all options and usage. PressQto quit. - Experiment in a Safe Environment: If possible, test complex or potentially disruptive commands on a non-critical Mac or a virtual machine first.
Conclusion
The Mac Terminal is a gateway to unparalleled control, customization, and efficiency for those willing to learn its language. The “secret” commands we’ve explored are just the tip of the iceberg, offering a glimpse into the vast potential that lies beneath the friendly macOS GUI. By mastering these commands, you transcend the role of a passive user and become an active participant in shaping your computing experience.
From unveiling hidden Finder settings and supercharging your system’s performance to conducting advanced network diagnostics and streamlining your development workflow, these commands empower you to truly unleash your Mac’s full potential. Remember the cardinal rule: proceed with caution, understand each command, and always have a backup. With practice and a healthy dose of curiosity, the Terminal will become one of your most powerful allies, transforming your Mac into a truly personalized and incredibly efficient powerhouse. So go forth, explore, and empower your macOS experience like never before!