I’ve started using Terminal on my Mac but only know a few basic commands. I’m looking for useful macOS Terminal tricks that can save time, improve productivity, and help me manage my system safely.
Terminal is not automatically faster or safer than Finder, so don’t start by copying random sudo commands from old blog posts. Before running anything destructive, use pwd to confirm your location and ls -la to inspect the files. Treat rm -rf as permanent because it bypasses the Trash, and quote paths containing spaces.
The macOS-specific commands are where Terminal becomes genuinely handy. open. opens the current folder in Finder, while open file.pdf launches a file in its default app. Pipe output to pbcopy, such as pwd | pbcopy, and use pbpaste to retrieve clipboard text. mdfind 'invoice' searches Spotlight from Terminal, caffeinate keeps the Mac awake while a task runs, and ditto source destination is often more suitable than cp for copying Mac folders and preserving metadata.
For everyday navigation, learn Tab completion, cd - to jump back to the previous directory, !! to repeat the last command, and Ctrl-R to search command history. Short aliases in ~/.zshrc can save typing, but keep them readable. Something like alias ll='ls -lah' is useful. An alias that silently adds sudo or force flags is asking for trouble.
A lot of flashy defaults write tricks age badly. They may stop working after a macOS update, or leave you wondering which hidden setting changed. I’d stick to commands that solve visible, repeatable tasks before tweaking system preferences from Terminal.
A few built-in tools are especially handy:
open -R file.txtreveals a file in Finder.open -a 'Preview' image.pngopens something in a specific app.qlmanage -p file.pdfgives you a Quick Look preview.sips -Z 1200 photo.jpgresizes an image while keeping its proportions.textutil -convert txt document.rtfconverts common document formats.du -sh * | sort -hshows what is taking up space in the current folder.networkQualityruns Apple’s basic network responsiveness test.
@kernelcraft is right about quoting paths, but beginners can often avoid typing them entirely: drag a file or folder from Finder into the Terminal window and macOS inserts its escaped path. I’d learn man command and command --help too. Knowing how to check a command’s options is more useful than collecting fifty tricks you won’t remember.
The hidden downside of Terminal is that the shell can expand a command before you realize how many files it matches. The warnings about rm are fair, but wildcards deserve equal suspicion. Before doing anything with *.jpg, preview the expansion:
printf '%s\n' *.jpg
For more complicated jobs, separate finding from changing. Run this first and inspect the output:
find ~/Downloads -type f -mtime +30 -print
Only after the list looks right should you build a move or delete command around it. Quoting variables matters for the same reason. Use '$file', not $file, or spaces and wildcard characters inside filenames can produce ugly surprises.
Learn redirection early because it turns Terminal into a decent troubleshooting notebook. > replaces a file, while >> appends to it. tee is useful when you want to see output and save it at the same time:
system_profiler SPHardwareDataType SPStorageDataType |
tee ~/Desktop/mac-report.txt
To capture errors along with normal output, use > report.txt 2>&1. Be careful with sudo and pipelines. In sudo command | other-command, only the first command receives elevated privileges. Redirection is handled by your existing shell, which is why adding sudo sometimes appears to do nothing. After an administrative task, sudo -k clears the cached authorization instead of leaving it available for the next command.
For actual Mac troubleshooting, a few read-only commands are more useful than hidden preference tweaks. pmset -g assertions shows processes that may be preventing sleep. lsof -nP -iTCP:3000 -sTCP:LISTEN identifies what is occupying port 3000. diskutil list displays disks and volumes without modifying them, and tmutil status shows whether Time Machine is currently working. If an app is misbehaving, top -o cpu can expose a CPU hog. Try a normal kill PID before reaching for kill -9, since the latter gives the process no opportunity to save data or clean up.
@reveurdenuit is right about checking documentation, although man pages can be rough when you do not yet know the command name. apropos sleep or man -k sleep searches manual-page descriptions. command -v name tells you what will actually run, which is worth checking after installing tools or creating aliases.
Once a sequence becomes repetitive, use a small shell function rather than a clever alias. For example, this creates a directory and enters it only if creation succeeds:
mkcd {
mkdir -p '$1' && cd '$1'
}
Put it in ~/.zshrc, then run source ~/.zshrc. Keep functions short enough that you can still understand them six months later. The most reliable Terminal habit is not memorizing exotic commands. It is previewing inputs, capturing output, and automating only after the manual version is predictable.
The hidden downside is that Terminal remembers your mistakes, including commands containing passwords, API keys, or other secrets. Shell history is convenient right up until history displays something you should never have pasted into a command line. Prefer prompts that read sensitive values privately, and check what you are about to expose with history 20. If a secret does land there, remove the relevant entry with history -d NUMBER, then assume the secret may need rotating. Also remember that clear only cleans the screen. It does not erase history, because apparently that would be too helpful.
A small correction to @goldendev8430’s examples: variables and function arguments normally need double quotes, not single quotes. Single quotes prevent expansion, so '$file' means the literal text $file, and mkdir -p '$1' creates a directory literally named $1. The function should be:
mkcd {
mkdir -p -- '$1' && cd -- '$1'
}
The -- tells commands that anything following it is a path, even if the name begins with a dash. While we are fixing tiny details that cause disproportionate confusion, the Finder command is open. with a space. open. is a different command name and usually just produces “command not found.”
My favorite macOS trick is making long jobs announce themselves instead of checking the window every thirty seconds:
long-command && say 'Finished'
For a normal notification instead of your Mac suddenly speaking during a meeting:
long-command && osascript -e 'display notification 'Task finished' with title 'Terminal''
Use && when success matters. Use ; if you want the notification even when the command fails. For something slightly more useful, capture the exit status:
long-command
status=$?
osascript -e 'display notification \'Exit status: $status\' with title \'Terminal\''
A few shell features save more time than collecting obscure commands. Ctrl-A and Ctrl-E jump to the beginning and end of the current line. Option-click usually moves the cursor to a position in the command. Ctrl-U removes text back to the start, Ctrl-K removes text to the end, and Ctrl-W deletes the previous word. If you mistype a long command, fc opens the previous command in your configured editor so you can fix it without playing arrow-key archaeology.
Finally, turn on protection against accidental output-file replacement in zsh:
setopt noclobber
Put that in ~/.zshrc. Afterward, command > existing-file.txt refuses to overwrite an existing file. You can deliberately override it with >|, which adds just enough friction to make you notice what you are doing. Terminal does not need to become a personality trait. A few editing shortcuts, correct quoting, notifications, and safer redirection cover a surprising amount of real work.
If your Mac is managed by an employer or school, throw out half of this advice before you try it. MDM profiles quietly revert defaults write tweaks, some sudo actions are blocked outright, and in a few setups your shell activity gets logged. So @reveurdenuit is right that hidden preference tricks age badly, but on a managed machine they don’t even age, they just never stick. Check for a config profile in System Settings before you waste an afternoon.
The thing that trips up almost every beginner and never gets mentioned: Terminal needs Full Disk Access to touch your own files. Run something harmless against your Desktop, Documents, or anything under ~/Library and you’ll hit ‘Operation not permitted’ out of nowhere. That’s not a broken command, it’s macOS privacy protection (TCC). You fix it once by adding Terminal (or whichever terminal app you use) under Privacy & Security, Full Disk Access, then restart the app. Until you do that, plenty of the commands above will look like they’re failing for mysterious reasons.
One more that saves confusion: the default shell has been zsh for years now, so any tutorial telling you to edit ~/.bash_profile is talking to a Mac from a decade ago. Put your aliases and functions in ~/.zshrc like the others said. And if you’d rather not memorize any of this, honestly just get comfortable with Tab completion and the history search first. Everything else is easier to pick up once you’re not fighting the basics.