Mac Terminal Commands Cheat Sheet

Quick reference for essential Terminal commands. Every command includes examples, flags, and links to learn more.

Want to actually learn these? Take the free course

File Operations

Create, read, copy, move, and delete files

tail

Learn in Module 3 →

Display the last 10 lines of a file.

tail logfile.txt
Flags & Options
-n 20 Show last 20 lines (or any number)
-f Follow: watch file for new lines in real-time

less

Learn in Module 3 →

View a file with scrolling. Press q to exit.

less longfile.txt
Flags & Options
Space Page down
b Page up
/ Search forward
q Quit

mkdir

Learn in Module 3 →

Make a new directory (folder).

mkdir NewFolder
Flags & Options
-p Create parent directories as needed

cp

Learn in Module 3 →

Copy a file or folder.

cp file.txt backup.txt
Flags & Options
-r Recursive: copy folders and their contents
-i Interactive: ask before overwriting

mv

Learn in Module 3 →

Move or rename a file or folder.

mv oldname.txt newname.txt
Flags & Options
-i Interactive: ask before overwriting

rm

Learn in Module 3 →

Remove (delete) a file. No trash, permanent deletion.

rm unwanted.txt
Flags & Options
-r Recursive: delete folders and their contents
-f Force: don't ask for confirmation
-i Interactive: ask before each deletion
Deleted files cannot be recovered. Use with caution.

open

Learn in Module 3 →

Open a file or folder with the default app.

open document.pdf
Flags & Options
-a AppName Open with a specific app
-e Open with TextEdit
. Open current folder in Finder

Clipboard & Redirection

Copy, paste, pipe, and redirect output

>

Learn in Module 7 →

Redirect output to a file (overwrites existing content).

ls > filelist.txt
This will overwrite the file without asking.

System & Utilities

Disk space, history, and system info

df

Learn in Module 10 →

Show disk space usage for all drives.

df -h
Flags & Options
-h Human-readable sizes (GB, MB instead of bytes)

du

Learn in Module 10 →

Show disk usage for files and folders.

du -sh *
Flags & Options
-s Summary (total for each argument)
-h Human-readable sizes
-d 1 Depth: only show 1 level deep

ipconfig

Learn in Module 10 →

Show network configuration.

ipconfig getifaddr en0
Flags & Options
getifaddr en0 Get IP address for primary network

Media & Archives

Images, compression, and downloads

sips

Learn in Module 10 →

Resize and convert images.

sips --resampleWidth 1200 *.jpg
Flags & Options
--resampleWidth N Resize to N pixels wide (keeps aspect ratio)
--resampleHeight N Resize to N pixels tall (keeps aspect ratio)
-s format jpeg Convert to JPEG format
-s format png Convert to PNG format

zip

Learn in Module 10 →

Create a compressed zip archive.

zip -r archive.zip folder/
Flags & Options
-r Recursive: include all files in subfolders

unzip

Learn in Module 10 →

Extract a zip archive.

unzip archive.zip
Flags & Options
-d folder Extract to a specific folder

curl

Learn in Module 10 →

Download files from URLs.

curl -O https://example.com/file.pdf
Flags & Options
-O Save with original filename from URL
-o filename Save with a custom filename
-L Follow redirects

Permissions & Config

File permissions, aliases, and environment

chmod

Learn in Module 8 →

Change file permissions.

chmod +x script.sh
Flags & Options
+x Add execute permission (make runnable)
-x Remove execute permission
755 Owner can read/write/execute, others can read/execute
644 Owner can read/write, others can only read

sudo

Learn in Module 8 →

Run a command as administrator.

sudo rm protected-file.txt
Be careful. Sudo bypasses safety restrictions.

Keyboard Shortcuts

Line Editing

Ctrl + A
Jump to beginning of line
Ctrl + E
Jump to end of line
Ctrl + U
Delete entire line
Ctrl + K
Delete from cursor to end of line
Ctrl + W
Delete word before cursor
Option + Delete
Delete word before cursor
Ctrl + Y
Paste deleted text back

Command History

Up Arrow
Previous command
Down Arrow
Next command
Ctrl + R
Search command history
Ctrl + G
Cancel history search

Terminal Control

Tab
Autocomplete file/folder names
Ctrl + C
Cancel current command
Ctrl + L
Clear screen (same as clear)
Cmd + K
Clear screen and scrollback
Ctrl + D
Exit Terminal (if line is empty)

Frequently Asked Questions

How do I open Terminal on Mac?

Press Cmd + Space to open Spotlight, type "Terminal", and press Enter. Or find it in Applications > Utilities > Terminal.

What is the Terminal command to see my current folder?

Use the pwd command (print working directory). It shows the full path of your current location.

How do I list all files including hidden files on Mac Terminal?

Use ls -a to show hidden files, or ls -la to show hidden files with details like size and date.

How do I delete a folder in Mac Terminal?

Use rm -r foldername to delete a folder and all its contents. Warning: this is permanent and cannot be undone.

How do I copy a file in Terminal?

Use cp source destination. For example: cp file.txt backup.txt. For folders, add -r: cp -r folder/ backup/

What does sudo mean in Terminal?

Sudo means "superuser do". It runs a command with administrator privileges, bypassing normal restrictions. Use carefully.

Ready to Actually Learn This?

This cheat sheet shows you what commands exist. The course teaches you when and why to use them.

Start the Free Course