Terminal

Mac Terminal Commands: The Ones Worth Knowing

Nemo · · 4 min read

The Mac Terminal commands you’ll use most are a short list: cd to change folder, ls to list it, pwd to see where you are, cp, mv and rm for files, mkdir for folders, and open to hand anything to its Mac app. Add grep and mdfind for searching and man for help, and you can handle a lot of everyday file work from the shell. macOS also has a few commands of its own, like pbcopy, caffeinate and say, that are specific to the Mac.

Why learn Terminal commands at all?

Because some jobs take many clicks and one typed line. Renaming a hundred files, finding every file that mentions a word, copying a folder while keeping hidden files, checking what’s eating disk space: each is a few clicks per item in Finder and one line in the shell. The catch is that the shell does exactly what you type, mistakes included, so it pays to know the handful of commands well rather than many of them badly.

Which commands move you around?

Command What it does
pwd Prints the folder you’re in
ls Lists the folder; ls -la adds hidden files and details
cd Documents Goes into a folder
cd .. Goes up one folder
cd ~ or cd Goes to your home folder
cd - Goes back to the previous folder
clear or Cmd+K Clears the screen

Tab completes file and folder names; when several match, the shell lists them.

Which commands work with files?

Command What it does
mkdir projects Makes a folder
touch notes.txt Makes an empty file (or updates its date)
cp a.txt b.txt Copies a file; cp -R for folders
mv a.txt docs/ Moves or renames
rm a.txt Deletes, with no Trash and no undo
cat file Prints a file
less file Pages through a file; q quits
du -sh * Shows the size of each item in the folder
df -h Shows free space on each disk

To see dotfiles in Finder as well, the guide to showing hidden files has the shortcut.

  • grep -r "TODO" . finds every line containing TODO under the current folder.
  • find . -name "*.pdf" finds files by name pattern.
  • mdfind "invoice" searches with Spotlight’s index, the same one Cmd+Space uses.
  • history | grep ssh finds a command you ran before.
  • man ls shows the manual for any command; q quits.

Which commands are Mac only?

Command What it does
open . Opens the current folder in Finder
open file.pdf Opens a file in its default app
open -a Preview file.png Opens it in a named app
pbcopy < file.txt Copies a file’s text to the clipboard
pbpaste > file.txt Writes the clipboard to a file
caffeinate Keeps the Mac awake until you press Ctrl+C
say "done" Speaks the text aloud
mdfind Searches with Spotlight
sw_vers Shows the macOS version
softwareupdate -l Lists available system updates

A handy pattern: npm test; say done tells you when a long command finishes.

How do you stay safe with rm and sudo?

rm skips the Trash, so check the path before pressing Return, and be very careful with rm -r. sudo runs a command as the administrator; use it only when you know why a command needs it. When a command came from a web page, read it first. Pasting a line into a shell runs whatever it says.

Where can you run these next to your browser?

Anywhere you have a shell. In Monok, a Mac browser with a native terminal, Ctrl+splits a terminal pane under the page running your own login shell, and>command` in an empty pane’s Magic Bar runs it once you press Return. No web page or JavaScript can reach that terminal. The built-in terminal post covers it, the tmux cheat sheet covers splitting panes, and the home page has the tour.

Try it: download Monok for Mac, free while in preview, macOS 14 or later.

FAQ

How do I open Terminal on a Mac?

Press Cmd+Space, type Terminal and press Return. It is also in Applications › Utilities.

What does sudo do?

It runs one command with administrator rights after asking for your password.

How do I stop a running command?

Press Ctrl+C.

Is Monok’s terminal a full shell?

Yes: your login shell with your rc files and tools. Get it on the download page.

More in Terminal

Contact

Bug reports, sites you want to see working, ideas. We reply by email.