Every programmer, sooner or later, ends up typing into a plain window with a blinking cursor: the terminal. It looks old-fashioned, and that's because it is. But it's also the fastest way to move around your files, run your code and use thousands of developer tools that have no buttons at all. This page teaches the dozen commands you'll use every single day, explains what a path is, and gives you a safe practice terminal right here in the page, where nothing you break is real.

What the terminal actually is

The terminal is a window where you talk to your computer in text instead of clicks. Inside it runs a program called the shell, which reads what you type, runs it, and prints the result. The most common shell is bash; macOS has used a close cousin called zsh by default since 2019. For everything on this page the two behave the same way.

How to open one:

When the window opens you'll see a prompt, something like ada@laptop:~$ or ada@laptop ~ %. It's the shell saying "I'm ready, type something". It usually shows your username, the computer's name and the folder you're in. The $ (bash) or % (zsh) marks where your typing starts. You never type the prompt itself.

Anatomy of a command

Every command follows the same shape: the command name, then optional options (also called flags) that tweak how it behaves, then arguments, which are the things it should act on. Spaces separate the pieces, so they matter.

$
lscommand
-aoption
Documentsargument

ls = list folder contents · -a = include hidden files · Documents = which folder to list. Press Enter to run it.

Options usually start with a dash. Single letters can be squashed together: rm -r -f and rm -rf mean the same thing. If a file name contains a space, wrap it in quotes, cat "my notes.txt", or the shell will think you meant two files, my and notes.txt. Commands are also case-sensitive: LS isn't ls.

Where am I? Paths

Your files are organised as a tree of folders (in the terminal, folders are usually called directories; same thing). At the very top is the root, written as a single /. Everything else sits somewhere inside it. Your personal files live in your home directory: /home/ada on Linux, /Users/ada on a Mac.

A path is the directions to a file or folder: folder names joined by slashes. /home/ada/Documents/notes.txt means "start at the root, go into home, then ada, then Documents, and there's notes.txt". (Windows uses backslashes, C:\Users\ada, but WSL and Git Bash use forward slashes like everyone else.)

The terminal is always "standing" in one folder, called the current working directory. That's what makes the two kinds of path work:

Three shortcuts appear in paths all the time: . means "this folder", .. means "the folder one level up" (the parent), and ~ (tilde) means "my home folder". Try some paths below and watch how the shell follows them, one slash at a time.

Path follower

    Notice that .. at the root just stays at the root: there's nothing above /. And notice how the same relative path can work from one folder and fail from another. When a command says No such file or directory, nine times out of ten you're simply standing in a different folder than you think. The cure is the first command below: pwd.

    Try it: your practice terminal

    This is a pretend terminal with a small pretend file system, so nothing here touches your real computer. It understands pwd, ls, cd, mkdir, touch, cat, echo, cp, mv, rm and clear, and its error messages are copied from a real Linux terminal. Follow the quest, or just play. The map beside it shows where you're standing; tap a folder in the map to get the cd command that would take you there.

    ada@laptop: ~

    Quest

      Where you are

      Hidden files (starting with a dot) aren't shown. Tap a folder to put a cd into the terminal.

      What each command did

      Every command name is a short, slightly cryptic abbreviation. Knowing what it stands for makes it much easier to remember.

      CommandWhat it does
      pwdprint working directoryShows the absolute path of the folder you're in.
      lslistLists what's in a folder. ls -a also shows hidden files.
      cd pathchange directoryMoves you into another folder.
      mkdir namemake directoryCreates a new, empty folder.
      touch name(touch a file)Creates an empty file, or just updates the "last modified" time if it exists.
      cat fileconcatenatePrints a file's contents. Give it several files and it prints them one after another.
      echo text(echo)Prints the text back. Handy with > to write into a file.
      cp from tocopyCopies a file. Add -r to copy a whole folder.
      mv from tomoveMoves or renames a file or folder.
      rm fileremoveDeletes a file. -r deletes a folder and everything in it.
      clearclearWipes the screen. Ctrl + L does the same.

      A few details worth knowing:

      rm has no undo

      There is no Trash in the terminal. Files deleted with rm are gone immediately. No "are you sure?", no Recycle Bin, no Cmd+Z.

      rm -r folder deletes the folder and everything inside it, and rm -rf adds "force": don't ask, don't complain. Before pressing Enter on any rm, run pwd and ls and read the command twice. Until you're comfortable, use rm -i, which asks before each file. And never paste a command you found online that contains rm unless you understand every part of it.

      Modern GNU rm does refuse rm -rf / (it says it is dangerous to operate recursively on '/'), but there's no such safety net for your home folder or your project. Back up anything you care about, and if your code lives in Git, commit often.

      Two habits that save hours: Tab and ↑

      Tab completion. Type the first few letters of a file, folder or command and press Tab. If only one thing matches, the shell finishes the name for you, even a long one. If several match, it fills in as much as they share; press Tab again and it lists the options. Experienced people press Tab constantly, not because they're lazy but because it makes typos impossible: if Tab won't complete a name, the name isn't there. Try it above: type cd Doc and press Tab (or the Tab button), or type cd P and press it twice.

      History. Press ↑ to bring back the previous command, again for the one before. Edit it and press Enter to run it again. And if something is running and won't stop, or you've typed a half-finished line you want to abandon, Ctrl + C cancels it.

      Check yourself

      You're in /home/ada/Documents. You run cd .. and then pwd. What's printed?

      .. is the parent folder, one level up. From Documents, that's /home/ada, and pwd prints it as a clean absolute path.

      What happens when you run rm notes.txt?

      rm deletes right away and prints nothing on success. Only rm -i asks first, and nothing puts the file in the Trash.

      todo.txt contains a ten-line list. You run echo "buy milk" > todo.txt. What's in the file now?

      A single > replaces the file's contents. To add a line to the end you'd use >>. Easy to mix up, and the mistake is silent.

      There's no folder called report-final.txt. What does mv report.txt report-final.txt do?

      Moving a file to a new name in the same folder is renaming. You don’t need a separate rename command: mv does both jobs.

      The short version

      Open a real terminal now and type pwd. That's it: you've started.