Unlock the Power of Your Mac with These 19 Must-Know Terminal Commands

default image

As a long-time Mac power user and data analyst, I‘m always surprised by how many Mac users don‘t realize the full potential of their machines. Behind the sleek graphical interface of macOS lies a powerful Unix-based foundation. And by tapping into this using the built-in Terminal app, you can unlock advanced capabilities and take control of your system like never before.

In this comprehensive guide from one Mac expert to another, I‘ll be sharing 19 awesome terminal commands I rely on to boost my productivity and efficiency as an Apple user. Whether you‘re a developer looking to optimize workflows, a data analyst needing more processing muscle, or a general user wanting to truly master your Mac – these terminal tricks will upgrade your skills.

Let‘s get started!

An Introduction to the Mac Terminal

For those new to the terminal – it‘s essentially an app that gives you direct access to the Unix command line on your Mac. Instead of clicking through windows and menus, you can type text commands to run programs, manipulate files, and configure settings.

Think of it as tapping into the raw power behind the friendly graphical interface of macOS. The terminal is always available, but most users don‘t know how to harness its potential.

Luckily, it‘s easy to get started! Here are two quick ways to open the terminal on any Mac:

Via Spotlight: Hit ⌘ Command+Spacebar to bring up Spotlight search, type in "Terminal", and hit Enter.

Through Finder: Hit ⌘ Command+N, navigate to Applications > Utilities, and double-click to open Terminal.

When launched, you‘ll see a window with a blinking cursor next to a dollar sign prompt. This is where you‘ll type commands, view program outputs, and control your system directly.

Now let‘s dive into the 19 most useful terminal commands I use daily as a Mac expert and data analyst. I think you‘ll be amazed by how much power is unlocked within just these few keystrokes!

1. View Hidden Files and Folders

By default, Mac OS hides certain system files and folders from users to prevent accidental changes or deletions. But as a power user, you may need access to these hidden resources.

Thankfully, just two quick terminal commands make them visible:

defaults write AppleShowAllFiles -bool TRUE
killall Finder

The first command sets the Finder preference to show hidden files. The second restarts the Finder app to apply the change.

Now you‘ll be able to traverse normally unseen directories like /usr, view dotfiles like .bashrc, and access resources that typically "disappear" in Finder. Tremendously useful for techies!

2. Keep Your Mac Awake

As a data analyst, I often have long-running jobs crunching datasets overnight. But I don‘t want my Mac going to sleep mid-process!

The caffeinate command tells a Mac to stay awake indefinitely until stopped:


Run this before starting a long task, and your Mac will not fall asleep. When finished, hit ⌃ Control+C to cancel the caffeination.

This one simple terminal command has saved me from many stalled half-finished processes. Never let your Mac nap on the job again!

3. Automate Software Updates

With all the active threats targeting Macs these days, keeping your system up-to-date is crucial. But checking manually through System Preferences can be tedious.

Instead, I‘ve created a terminal command that programmatically checks and installs any available macOS updates daily:

softwareupdate -l | grep ‘*‘ | sed ‘s/* //‘ | xargs -I {} sudo softwareupdate -i {}  

Here‘s how it works:

  • softwareupdate -l lists available updates
  • grep ‘*‘ filters to just updates ready to install (marked with *)
  • sed ‘s/* //‘ removes the * marker from update names
  • xargs takes the update list and passes each to softwareupdate -i to install

Scheduled as a cron job, this automatically keeps my system patched without any effort. Feel free to steal this one for your Mac!

4. Turbocharge File Downloads

downloads files from the command line using curl:

curl -O

The -O flag names the downloaded file as it‘s named on the server.

I love the increased visibility curl provides into download speeds, progress bars, and output files. No need to drop into a web browser just to grab a file.

curl works with HTTP, HTTPS, FTP, and more. You can resume interrupted transfers, download specific byte ranges, and even pass HTTP headers. Much more powerful than clunky web download UIs!

5. Force Quit Unresponsive Apps

We‘ve all experienced the frustration of an application freezing up and becoming unresponsive. Sure, you can always restart your Mac, but that takes time and disrupts workflows.

Instead, I use two terminal commands to precisely target and force quit just the affected app:

Find the Process ID (PID):

ps aux

This lists all running processes. Locate the PID of the culprit app.

Force Quit Process by PID:

kill <pid> 

Bye bye, frozen app! The rest of the system remains undisturbed.

For frequently troublesome apps like Slack or Adobe CC, I‘ve even created terminal aliases that directly kill them by name:

alias killslack=‘killall "Slack"‘

Two keystrokes and Slack is quit without the beachball of doom!

6. Maintain Your Privacy

Maintaining privacy is vital these days, and your Mac terminal history is no exception.

To remove the current session‘s history:

history -c

This wipes out any confidential commands you may have entered.

For a complete purge of the permanently stored history:

rm ~/.bash_history

I run this often to cover my tracks – no more worrying about exposing API keys, IPs, or other sensitive info. Try it yourself!

7. Organize Your Screenshots

As a digital hoarder of screenshots, my desktop was always cluttered with images. But the terminal helped me instantly get organized with just a few commands.

First, check your current screenshot save location:

defaults read location   

Then set a new location like your Documents or Pictures folder:

defaults write location ~/Documents/Screenshots/

Finally, apply the change:

killall SystemUIServer

Voila – screenshots now saved to the proper place every time!

You can also customize the name format, file type (JPG, PNG, PDF), and more. Try these additional defaults write commands:

# Name screenshots "screenshot"
defaults write name "screenshot"

# Change format to PNG 
defaults write type png

8. Show/Hide Useful Interface Elements

macOS offers some handy optional interface elements that are worth toggling on for power users:

Show full path in Finder title bar:

defaults write _FXShowPosixPathInTitle -bool TRUE

Show hidden files in Open/Save dialogs:

defaults write AppleShowAllFiles -bool TRUE 

Show all filename extensions:

defaults write NSGlobalDomain AppleShowAllExtensions -bool TRUE

Conversely, you can also hide some unnecessary clutter:

Hide Dashboard:

defaults write mcx-disabled -bool TRUE  

Remove useless Dashboard widget:

rm -rf /Applications/

Run killall Dock or Finder after to apply changes. I tweaked all these settings to optimize my UI for productivity – you should too!

9. Review System History Logs

As a technologist, I‘m a huge fan of macOS‘s comprehensive system logs. Need to troubleshoot why an app crashed or a CPU is spiking? Just browse the logs!

# View general system log
less /var/log/system.log 

# Monitor kernel/OS messages 
sudo log stream --info

# Watch for security events  
sudo log stream --predicate ‘eventMessage contains "sudo"‘

Some other useful logs to explore:

  • /var/log/install.log: Software installation history
  • /var/log/ iCloud sync issues
  • /Library/Logs/DiagnosticReports: Crash reports
  • /private/var/log/asl/: Filtered by source/app

These insights have helped me diagnose and fix many system issues over the years. Take advantage of them yourself!

10. Monitor System Resources

Is your Mac feeling sluggish? Using too much memory? With a few terminal commands, you can monitor system resources to identify any bottlenecks.

To view overall CPU usage and load averages:


Sort processes eating up the most CPU:

top -o cpu -s 5

Check memory consumption by app:

ps aux -sort=-rss | head

And keep an eye on disk I/O with iotop:

brew install iotop ; iotop

With this data, I can isolate heavy processes, troubleshoot performance issues, and regain speed on a lagging Mac. You can even log usage over time with utility scripts!

11. Securely Delete Files

As a security-focused Mac user, I want to ensure deleted files are completely erased when needed. macOS‘s default behavior leaves data recoverable.

Instead, I use srm (secure remove) which overwrites files multiple times to prevent undeletion:

srm /path/to/file

You can optionally specify the number of overwrite passes (I use 35):

srm -m 35 /path/to/file

For wholesale secure deletion of a disk or drive, use:

diskutil secureErase freespace LEVEL /Volumes/DRIVE

Set LEVEL to 1 for a quick overwrite or higher for multiple passes. Don‘t let deleted data stick around!

12. Batch Optimize Images

Working with lots of screenshots, graphics, and photos? The terminal makes it easy to optimize them all for size and format.

Convert JPGs to efficient JPG2000 format:

mogrify -format jpg2k *.jpg

Resize all images to 1000px wide:

mogrify -resize 1000 *.jpg *.png

Reduce PNG file sizes with TinyPNG compression:

tinypng *.png

Batch convert HEIC photos from iPhone to JPG:

brew install imagetragick ; imagetragick *.heic -o *.jpg

A few imagemagick commands like these save me tons of time processing visual assets!

13. Automate Repetitive Tasks

Like any good programmer, I‘m always seeking ways to eliminate repetitive manual work through automation. Here are some of my favorite time-saving terminal tricks:

Schedule macOS updates:

0 0 * * * softwareupdate -l | grep ‘*‘ | sed ‘s/* //‘ | xargs -I {} sudo softwareupdate -i {}

Nightly backups:

0 2 * * * rsync -avzh /Users/ ~/"Backups"/$(date +%Y-%m-%d)

Regular restarts:

0 0 */7 * * sudo shutdown -r now

Monthly maintenance:

0 0 1 * * sudo periodic daily weekly monthly

With just a bit of cron scheduling, these routines now run automatically in the background without my involvement. Let the terminal work for you!

14. Bulk Generate Reports

As a data analyst, generating insights from results sets is a big part of my job. I used to export tables manually into Excel or Google Sheets for reporting – ugh!

Now I craft terminal commands like this one to automate bulk PDF report generation from any tabular text file:

cat results.tsv | datatable -f tsv --maxrows 500 \
   --title "Q3 Sales Report" --caption "Report Run Date: $(date)" \
   -p report.pdf

The datatable program converts TSV data into a nicely formatted PDF report with just a single command.

I have similar routines configured for CSVs, databases, API responses, and more. Stop the repetitive cutting and pasting – make your terminal crunch numbers instead!

15. Get Weather Reports

To quickly check the weather forecast, traditional developers would likely call a weather API from their language or environment of choice.

But with the power of the terminal, it only takes one command using the service:


This returns a beautifully formatted weather report with emoji right in the terminal!

Specify a location like:


Or get a concise 2 day forecast with:


Next time you need a fast weather check, let your terminal handle it in seconds!

16. Check Website Uptime

Monitoring website uptime is critical when managing servers and services. But constantly loading sites manually is tiresome.

Instead, I ping sites directly from terminal to check HTTP status and response times:


Or request just the headers to isolate server issues:

curl -I 

Taking it further, you can write a monitoring script that pings critical sites and emails alerts. Here‘s an example in Python:

import subprocess
import smtplib

sites = ["",""]

for site in sites:
  response ="ping -c 1 " + site, shell=True) 

  if response.returncode == 0:
    print(site, "OK")
    print(site, "DOWN")    
    # Send alert email
    server = smtplib.SMTP(‘‘, 587)
      "[email protected]",
      "[email protected]",
      site + " is down!")

Automate your website monitoring with the power and flexibility of terminal scripting!

17. Search File Contents

Need to find where a specific term, code snippet, or text pattern occurs in a file? The terminal makes it easy with grep.

To search for "macOS" in this guide:

grep "macOS"

You can recursively search entire folder structures using:grep -R "search phrase" /path/to/folder

grep has tons of useful options:

  • -i for case-insensitive matches
  • -B shows lines before each match
  • -A shows lines after each match
  • -C specifies lines of context around matches
  • -c just shows a count of matches

Whenever I need to hunt down a phrase in projects, logs, or other text corpora, grep is my go-to!

18. Stay in Your Shell

Bouncing between graphical apps in macOS can disrupt your terminal workflow. With the power of shells like Zsh and tools like Homebrew, many tasks can be done without ever leaving the command line.

A few things I now extensively use through terminal:

  • ncdu – disk usage analyzer
  • neofetch – display system info
  • peek – screen recorder
  • m-cli – access Apple Music
  • newsboat – RSS reader
  • jrnl – take notes

Plus a whole suite of single-purpose utilities from brews like wget, tree, nmap, exiftool and more. Try spending a full day in your shell – you may never leave!

19. Explore New Possibilities

Hopefully this guide has shown you how much additional productivity and control is available on your Mac through the humble terminal.

Here are some ideas for continuing your journey:

  • Look up man pages for commands you use often to uncover additional options and capabilities

  • Check out shell packages like Oh My Zsh to expand what your terminal can do

  • Learn a scripting language like Python, Ruby, or Bash to combine commands into advanced workflows

  • Watch for interesting utilities on GitHub – developers are always releasing great new terminal tools

  • Ask fellow Mac power users for their favorite commands and tweaks to discover more

The terminal is the gateway to unlocking the full potential of your Mac. I hope these 19 commands provide a solid foundation as you delve further into this world and make the shell an indispensable part of your daily workflow.

Happy hacking!

Written by