Basic Terminal Commands

Essential command line operations for navigating files, managing folders, and getting things done in the terminal

The terminal (or command line) lets you control your computer by typing commands instead of clicking around. It's faster for many tasks once you know the basics, and some things can only be done here. This guide covers the commands you'll use most.

On macOS, the terminal app is called Terminal. Open it from Applications > Utilities > Terminal, or press Cmd + Space and type "Terminal".

macOS uses zsh as its default shell (older Macs used bash – the commands below work in both).

Navigating around

  • pwd – print where you currently are (your "working directory")
  • ls – list files and folders in the current directory
  • ls -la – list everything including hidden files, with details
  • cd Documents – move into the Documents folder
  • cd .. – go up one level
  • cd ~ – go to your home folder
  • cd / – go to the root of the drive

Creating and removing

  • mkdir project – create a folder called "project"
  • mkdir -p project/src/components – create nested folders in one go
  • rmdir project – remove an empty folder
  • rm file.txt – delete a file (no trash, it's gone)
  • rm -r project – delete a folder and everything inside it (be careful)

Copying and moving

  • cp file.txt backup.txt – copy a file
  • cp -r folder/ folder-backup/ – copy a folder and its contents
  • mv file.txt Documents/ – move a file into Documents
  • mv oldname.txt newname.txt – rename a file

Viewing file contents

  • cat file.txt – print the entire file
  • less file.txt – scroll through a file (press q to quit)
  • head -20 file.txt – show the first 20 lines
  • tail -20 file.txt – show the last 20 lines

Finding files

  • find . -name "*.txt" – find all .txt files in the current folder and subfolders
  • find ~/Documents -name "report*" – find files starting with "report" in Documents

Permissions and admin

  • chmod +x script.sh – make a file executable
  • chmod 644 file.txt – set read/write for you, read-only for others
  • sudo command – run a command as admin (you'll need your password)

Handy tricks

  • Press Up Arrow to cycle through previous commands
  • Press Tab to auto-complete file and folder names
  • Press Ctrl + C to cancel a running command
  • history – see your command history
  • clear – clear the screen

Frequently Asked Questions

Will I break something by using the terminal?

Most commands are safe, but rm (delete) and sudo (admin) commands should be used carefully. Unlike dragging a file to the trash, rm deletes permanently with no undo. Double-check the path before running destructive commands.

What's the difference between Terminal, Command Prompt, PowerShell, and shell?

A "shell" is the program that reads your commands. Bash and zsh are shells on Mac/Linux, PowerShell is the modern shell on Windows. "Terminal" and "Command Prompt" are the apps that give you a window to type in. Think of the terminal as the window and the shell as the engine inside it.

Do I need to memorize all these commands?

No. Most people use the same 5-10 commands daily (cd, ls, mkdir, cp, mv, rm, cat). Bookmark this page or keep a cheat sheet handy until they become muscle memory. The Up Arrow and Tab keys do a lot of the heavy lifting.

How do I know which folder I'm in?

Run pwd (macOS, Linux, PowerShell). It prints the full path to your current location. If you're lost, cd ~ takes you home.

Can I undo a command?

There's no universal undo. For file operations, once a file is deleted with rm or del, it's gone. For other mistakes, Ctrl + C cancels a running command before it finishes. Get in the habit of double-checking before pressing Enter on destructive commands.