keepcalculator

06 Numbers and Powers

Mac Terminal Commands You Should Try

Card No. 06·38716 · Updated · Standard formula, shown below

If you want to get more out of your Mac, learning a handful of Terminal commands is one of the fastest ways to feel like a power user. This article walks you through the most useful commands for everyday tasks—file management, system monitoring, network troubleshooting, and customization—with clear explanations of what each one does and how to read its output. You don’t need to be a programmer to benefit; these commands are safe, practical, and immediately usable.

Why the Terminal Matters on macOS

macOS is built on Unix, and the Terminal app gives you direct access to that Unix core. While the Finder and System Settings cover most daily tasks, the command line lets you do things faster, see more detail, and automate repetitive work. For example, you can rename hundreds of files in one line, find exactly which process is hogging your CPU, or download a file from the web with a single command. It also helps you understand how your Mac really works—something that becomes invaluable when you run into a problem that has no obvious fix in the graphical interface.

Every command you type is executed by a shell, which on modern macOS is zsh (since Catalina). The shell interprets your words and tells the operating system what to do. You don’t need to memorize everything; even learning a dozen commands will change how you use your Mac.

File and Folder Commands You’ll Use Daily

The most basic commands are about navigating and manipulating files. They mirror what you do in the Finder, but with more power and precision.

  • ls – Lists files and folders. Use ls -la to see hidden files (those starting with a dot) and detailed permissions.
  • cd – Changes directory. cd Documents moves into your Documents folder; cd .. goes up one level.
  • cp – Copies files or folders. cp file.txt backup.txt creates a copy; add -R for folders.
  • mv – Moves or renames. mv old.txt new.txt renames, and mv file.txt ~/Desktop/ moves it to your Desktop.
  • rm – Deletes files. Be careful: rm file.txt permanently deletes it, bypassing the Trash. Use rm -i to be prompted before each deletion.
  • mkdir – Creates a new folder. mkdir Projects makes a folder named Projects.
  • open – Opens files or folders in their default app. open . opens the current folder in the Finder, and open image.png opens that image in Preview.

One particularly handy trick is open -a "Safari" https://example.com, which opens a specific website in Safari from the command line. You can also use open -e file.txt to open a text file in TextEdit.

Finding Things: grep, find, and Spotlight

Searching from the Terminal is often faster and more precise than using the Finder’s search.

  • grep – Searches inside files for text. For example, grep "error" ~/Documents/log.txt shows every line containing “error”. You can add -i to ignore case, and -r to search recursively in a folder.
  • find – Finds files by name, type, or other attributes. find ~/Downloads -name "*.pdf" lists all PDFs in your Downloads folder. Add -size +100M to find files larger than 100 MB.
  • mdfind – Uses the same index as Spotlight. mdfind "kind:image" returns all images on your Mac, and you can narrow it with -onlyin ~/Documents.

A common mistake is mixing up grep and find: grep searches text inside files, while find searches for files themselves. If you want to find a file whose name you partially remember, find is your friend; if you want to find a line of code or a word inside a document, use grep.

Monitoring Your Mac: top, ps, and df

When your Mac feels slow, the Terminal can tell you exactly what’s happening.

  • top – Shows a live list of processes, sorted by CPU usage. Press q to quit. The column labeled %CPU shows how much of your processor each process is using; if one process is consistently above 100%, it’s likely the culprit.
  • ps aux – Takes a snapshot of all running processes. ps aux | grep "Safari" shows only processes with “Safari” in their name, which is useful for finding a stuck app’s process ID (PID).
  • df -h – Shows disk space usage in human-readable format (e.g., 500 GB). The / row is your startup disk; if it shows 90% full, you know it’s time to clean up.
  • du -sh * – Shows the size of every file and folder in the current directory. Run du -sh * | sort -h to see the largest items at the bottom.

To quit a stubborn process, you can use kill followed by the PID. For example, kill 1234 sends a polite stop signal; if that doesn’t work, kill -9 1234 forces it. Use kill -9 as a last resort because it doesn’t let the app save data.

Network Commands for Troubleshooting

If your Wi-Fi drops or a website won’t load, these commands help you diagnose the problem.

  • ping – Sends a small packet to a server and measures the response time. ping -c 5 google.com sends 5 pings and stops. If you see “Request timeout” or high latency, your connection is unstable.
  • curl – Transfers data from or to a server. curl -I https://example.com fetches just the HTTP headers, which shows if the site is reachable and what server software it runs. curl -O https://example.com/file.zip downloads a file.
  • nslookup – Looks up the IP address for a domain. nslookup example.com tells you which server is responsible for that domain, which helps distinguish DNS problems from connection problems.
  • netstat -nr – Shows the routing table, including your default gateway (usually your router’s IP). This is useful when you can’t reach the internet but your Mac is connected to Wi-Fi.

A common question is whether ping is safe to run. Yes, it’s harmless—it just sends a few bytes. However, some servers block ping for security, so a timeout doesn’t always mean the server is down.

Customizing Your Terminal and Shell

Your Terminal doesn’t have to look like a white box with black text. You can change the theme, add aliases, and create functions to speed up your workflow.

  • Change the theme – In Terminal’s Preferences (Cmd+,), go to Profiles and choose a different color scheme. You can also download custom themes from the web.
  • Aliases – Add shortcuts to your ~/.zshrc file. For example, alias ll='ls -la' lets you type ll instead of the full command. After editing, run source ~/.zshrc to apply changes.
  • Set your prompt – The prompt is the text before your cursor. You can customize it to show the current folder, git branch, or even the time. For example, export PS1='%n@%m %~ %# ' shows username, hostname, and current directory.
  • Use history – Type history to see every command you’ve typed. Press Ctrl+R to search through it interactively.

One of the most useful aliases is alias showfiles='defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder', which reveals hidden files in the Finder. To hide them again, change true to false.

Frequently Asked Questions

Is it safe to use Terminal commands?

Most commands are safe, but some can permanently delete files or change system settings. Always double-check a command before running it, especially if it includes rm, sudo, or defaults write. If you’re unsure, search for the command online or add --help to see its options.

What does sudo do and should I use it?

sudo runs a command with administrator privileges. It’s necessary for some system-level tasks, but it can be dangerous if used incorrectly. You’ll be prompted for your password, and it’s wise to only use sudo when you understand exactly what the command does.

How do I quit a frozen app from the Terminal?

Use ps aux | grep "AppName" to find the process ID, then kill PID. If that doesn’t work, try kill -9 PID. Alternatively, pkill AppName kills the process by name, but be careful—it might kill multiple instances.

Can I undo a command I just ran?

No, the Terminal doesn’t have an undo feature. This is why it’s crucial to be careful with destructive commands like rm. For file deletion, consider using trash (a third-party tool) or moving files to a temporary folder instead of deleting them outright.

Why does my Terminal say zsh: command not found?

That means the command you typed isn’t installed or isn’t in your PATH. Check the spelling, or install the software that provides it (like Homebrew for package installs). If the command is in a different location, you can add it to your PATH in ~/.zshrc.

What is the difference between ~, ., and ..?

~ is your home directory (e.g., /Users/yourname). . refers to the current directory, and .. refers to the parent directory. So cd .. goes up one folder, and cd ~ returns to your home folder.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →