Cheatsheet: macOS Command Line
This is your zero-fluff, beginner-friendly, builder-focused guide to using Terminal on macOS — the essential skill for developers, automation work, and real-world problem solving.
Why Terminal Even Matters (And Why Builders Use It)
Let's be honest — most people can live their entire Mac life without touching Terminal. But the moment you start building anything serious — projects, scripts, APIs, deployments, automation — the mouse starts getting in your way.
The Terminal gives you precision. You tell the machine exactly what you want, no clicks, no spinning beach balls. Tasks that take minutes in Finder can take seconds here — and in many cases, this is the only way you'll be able to interact with remote servers, repositories, cloud deployments, and dev environments.
- Setting up developer environments (Python, Node, Docker, Homebrew)
- Managing files across multiple projects fast
- Using Git or connecting to remote servers via SSH
- Running backend scripts, build systems, or automation tasks
- Debugging network, permission, or system-level issues
So instead of dreading it, let's demystify it — you'll see that many Terminal commands are shockingly simple once you know the flow.
Opening Terminal
Terminal is pre-installed on macOS. You do not need to install any additional software to start using it.
To open Terminal:
- Press Command (⌘) + Space to open Spotlight Search.
-
Type
Terminaland press Return. - Alternatively, go to Applications → Utilities → Terminal.
Tip: Right-click the Terminal icon in your dock and select Options → Keep in Dock for quick access.
When Terminal opens, you'll see a prompt similar to:
your-macname:~ username$
This prompt is where you type commands.
Understanding Directories
macOS organizes files into a directory structure (folders). Every file and folder exists inside this hierarchy.
Key Directories
-
/— Root directory (top level of the system) -
/Users/your-username/— Your personal home directory -
~— Shortcut that always refers to your home directory
Check Current Directory
Use pwd to display your current directory (Print
Working Directory):
pwd
List Files and Folders
Use ls to list the contents of the current
directory:
ls
To show all files, including hidden files (those starting with a dot):
ls -la
Note: Hidden files are commonly used for configuration (e.g.,.gitignore,.env).
Navigating Directories
Use the cd (Change Directory) command to move
between directories.
Basic Navigation
- Go into a directory:
cd directory-name
- Go up one level:
cd ..
- Return to your home directory:
cd ~
- Go directly to any absolute path:
cd /Users/your-username/projects
Tip: You can drag and drop a folder into Terminal to automatically fill in its full path.
Managing Files and Folders
Create a New Directory
Use mkdir to create a new folder:
mkdir new-folder
Create a New File
Use touch to create an empty file:
touch file.txt
Move or Rename Files
mv moves files or renames them:
- Move file to another directory:
mv file.txt ~/projects/
- Rename a file:
mv oldname.txt newname.txt
Copy Files
Use cp to make a copy of a file:
cp file.txt ~/projects/
Delete Files
Use rm to delete files:
rm file.txt
Delete Folders
Use rmdir to delete empty folders:
rmdir folder-name
Use rm -r to delete folders with contents
(recursive delete):
rm -r folder-name
Caution: rm -r deletes everything
inside the folder permanently. Use carefully.
Working with Hidden Files
Files or folders that start with a dot (.) are
hidden by default on macOS. These are often used for
configuration files (e.g., .gitignore,
.env).
View Hidden Files
Use ls -la to show all files, including hidden
ones:
ls -la
Create a Hidden File
Use touch to create hidden files:
touch .env
Edit a File Using nano
nano is a built-in text editor inside Terminal:
nano .env
After editing:
- Press Control + X to exit
- Press Y to confirm save
- Press Return to write changes
View File Contents
Use cat to display file contents directly in the
Terminal:
cat .env
Tip: Hidden files are widely used in software projects to store credentials, configuration, and environment variables. Always handle them carefully.
Useful Terminal Commands & Tips
Besides basic file management, these commands can help you work faster on macOS:
Open Finder from Terminal
Open the current directory in Finder:
open .
Copy Command Output to Clipboard
Use pbcopy to copy output directly to clipboard:
ls -la | pbcopy
Paste Clipboard Contents into Terminal
pbpaste
See Your Command History
List previously executed commands:
history
Clear Terminal Screen
Clear current screen:
clear
Shortcut: Auto-Complete Paths
Use Tab to auto-complete file or directory names:
cd Doc[TAB]
Shortcut: Previous Commands
Use the Up Arrow to scroll back through recent commands without retyping them.
Tip: Use these shortcuts often — they save time and reduce typing mistakes.
Practice Exercises
Try these exercises to practice the commands covered above:
-
Print your current directory:
bash
pwd -
List all files, including hidden files, in your home
directory:
bash
ls -la ~ -
Create a new directory called
projectsinside your home folder:bashcd ~ mkdir projects -
Create a new file called
notes.txtinsideprojects:bashcd projects touch notes.txt -
Edit
notes.txtusingnano:bashnano notes.txt -
Copy
notes.txtto a new file calledbackup.txt:bashcp notes.txt backup.txt -
Move
backup.txtback to your home directory:bashmv backup.txt ~ -
Delete
backup.txtfrom your home directory:bashrm ~/backup.txt -
Create a hidden file
.configinsideprojects:bashcd ~/projects touch .config nano .config -
View contents of
.config:bashcat .config -
Delete the entire
projectsdirectory and all its contents:bashcd ~ rm -r projects
Reminder: Be careful with rm -r.
It permanently deletes files and folders without confirmation.
Summary
Terminal on macOS gives you full control over your system, files, and development environment. Even with just the basic commands covered here, you can navigate, create, edit, move, and delete files much faster than through the graphical interface.
As you continue using Terminal, you'll find many tasks become easier and more efficient once you're comfortable with the command line. These skills are also foundational if you plan to work with version control (Git), servers (SSH), package managers (Homebrew), or automation scripts.
- Practice regularly to build familiarity.
-
Explore package managers like
brewto install developer tools. - Learn basic Git commands for version control.
- Experiment with simple shell scripts for automation.
Terminal is a core skill for developers, system administrators, and anyone working with code or automation. The more you practice, the more natural it becomes.