Insights Videos Blog Learning
CHEATSHEET

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.

When You Can't Avoid Terminal Anymore:
  • 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 Terminal and 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:

bash
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):

bash
pwd

List Files and Folders

Use ls to list the contents of the current directory:

bash
ls

To show all files, including hidden files (those starting with a dot):

bash
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:
bash
cd directory-name
  • Go up one level:
bash
cd ..
  • Return to your home directory:
bash
cd ~
  • Go directly to any absolute path:
bash
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:

bash
mkdir new-folder

Create a New File

Use touch to create an empty file:

bash
touch file.txt

Move or Rename Files

mv moves files or renames them:

  • Move file to another directory:
bash
mv file.txt ~/projects/
  • Rename a file:
bash
mv oldname.txt newname.txt

Copy Files

Use cp to make a copy of a file:

bash
cp file.txt ~/projects/

Delete Files

Use rm to delete files:

bash
rm file.txt

Delete Folders

Use rmdir to delete empty folders:

bash
rmdir folder-name

Use rm -r to delete folders with contents (recursive delete):

bash
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:

bash
ls -la

Create a Hidden File

Use touch to create hidden files:

bash
touch .env

Edit a File Using nano

nano is a built-in text editor inside Terminal:

bash
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:

bash
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:

bash
open .

Copy Command Output to Clipboard

Use pbcopy to copy output directly to clipboard:

bash
ls -la | pbcopy

Paste Clipboard Contents into Terminal

bash
pbpaste

See Your Command History

List previously executed commands:

bash
history

Clear Terminal Screen

Clear current screen:

bash
clear

Shortcut: Auto-Complete Paths

Use Tab to auto-complete file or directory names:

bash
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:

  1. Print your current directory:
    bash
    pwd
  2. List all files, including hidden files, in your home directory:
    bash
    ls -la ~
  3. Create a new directory called projects inside your home folder:
    bash
    
    cd ~
    mkdir projects
  4. Create a new file called notes.txt inside projects:
    bash
    
    cd projects
    touch notes.txt
  5. Edit notes.txt using nano:
    bash
    nano notes.txt
  6. Copy notes.txt to a new file called backup.txt:
    bash
    cp notes.txt backup.txt
  7. Move backup.txt back to your home directory:
    bash
    mv backup.txt ~
  8. Delete backup.txt from your home directory:
    bash
    rm ~/backup.txt
  9. Create a hidden file .config inside projects:
    bash
    
    cd ~/projects
    touch .config
    nano .config
  10. View contents of .config:
    bash
    cat .config
  11. Delete the entire projects directory and all its contents:
    bash
    
    cd ~
    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.

Next Steps:
  • Practice regularly to build familiarity.
  • Explore package managers like brew to 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.