Skip to content
FLAVIO COPES
flaviocopes.com

How to use the macOS terminal

By

Learn how to open and use the macOS Terminal, understand the zsh prompt, navigate files and folders, run commands safely, and get command help.

~~~

Terminal is the command-line application included with macOS.

Each Terminal window runs a shell. On current macOS versions the default shell is zsh, which reads the commands you type and starts the corresponding programs.

Open Terminal

Open Spotlight with Command + Space, type Terminal, and press Return.

You can also open Finder and go to Applications → Utilities → Terminal.

Apple’s Terminal User Guide documents the application and its settings.

Understand the prompt

A new window shows a prompt similar to:

flavio@MacBook ~ %

The exact text depends on your settings.

~ represents your home directory. % is a common zsh prompt symbol. The prompt means the shell is waiting for a command; you do not type the prompt itself.

Check the login shell configured for your account:

echo "$SHELL"

Check the shell running in the current window:

ps -p $$ -o command=

The two can differ if you started another shell manually.

See your current directory

Print the current working directory:

pwd

A macOS home directory normally looks like:

/Users/yourname

List the files and folders in the current directory:

ls

Include hidden names:

ls -a

Names beginning with . are hidden by convention.

Change directory

Move into your Downloads directory:

cd ~/Downloads

Move to the parent directory:

cd ..

Return home:

cd

Paths containing spaces must be quoted or escaped:

cd "~/My Folder"

That example contains a subtle mistake: ~ does not expand inside double quotes. Quote only the part that needs it:

cd ~/"My Folder"

You can also drag a file or folder from Finder into Terminal to insert its escaped path.

Create, copy, move, and remove files

Create a directory:

mkdir experiments

Create an empty file:

touch notes.txt

Copy it:

cp notes.txt notes-copy.txt

Rename or move it:

mv notes-copy.txt archive.txt

Remove a file:

rm archive.txt

rm does not move the file to the Trash. Check the path before pressing Return, and be especially careful with recursive or forced removal options.

Open Finder or an application from Terminal

Open the current directory in Finder:

open .

Open a file with its default application:

open notes.txt

Open an application:

open -a "Visual Studio Code"

Run development tools

Terminal can run any command installed on your system.

For example, after installing Node.js, verify it:

node --version
npm --version

Then run a JavaScript file:

node app.js

If a command is not found, do not download a random binary from an error message or use sudo without understanding why. Install the tool from its official source or a trusted package manager.

Get help

Read a command’s manual page:

man ls

Press q to leave the manual.

Many commands also support:

command --help

Find how the shell resolves a command:

command -v node

Use clear to clear the visible terminal and the Up arrow to revisit command history.

Stop or leave

Press Control + C to ask a running foreground command to stop.

Close the shell session cleanly with:

exit

The terminal is powerful because commands can change many files quickly. Start with small commands, quote paths, and read a command’s help before using destructive options.

Tagged: Mac · All topics
~~~

Related posts about mac: