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.
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:
Cmd + Space, type Terminal, press Enter. (It lives in Applications › Utilities.)Ctrl + Alt + T opens one.wsl --install), which gives you a real Linux terminal. A lighter option is Git Bash, which comes with Git for Windows.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.
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.
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.
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:
/. It begins at the root, so it means the same thing wherever you are.Documents/notes.txt only works if you're in the folder that contains Documents.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.
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.
Hidden files (starting with a dot) aren't shown. Tap a folder to put a cd into the terminal.
Every command name is a short, slightly cryptic abbreviation. Knowing what it stands for makes it much easier to remember.
| Command | What it does |
|---|---|
pwdprint working directory | Shows the absolute path of the folder you're in. |
lslist | Lists what's in a folder. ls -a also shows hidden files. |
cd pathchange directory | Moves you into another folder. |
mkdir namemake directory | Creates a new, empty folder. |
touch name(touch a file) | Creates an empty file, or just updates the "last modified" time if it exists. |
cat fileconcatenate | Prints 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 tocopy | Copies a file. Add -r to copy a whole folder. |
mv from tomove | Moves or renames a file or folder. |
rm fileremove | Deletes a file. -r deletes a folder and everything in it. |
clearclear | Wipes the screen. Ctrl + L does the same. |
A few details worth knowing:
cd on its own takes you home, from anywhere. cd - jumps back to the folder you were in before..bashrc (which holds settings for bash). ls -a also lists . and .., because every folder contains those two shortcut entries.mkdir -p a/b/c creates all three nested folders in one go. Without -p, mkdir refuses if a doesn't exist yet.> and >> send a command's output into a file instead of the screen. echo "hi" > note.txt replaces everything in note.txt; >> adds to the end. This works with any command: ls > list.txt saves the listing.mv is also rename. mv draft.txt final.txt renames the file. If the destination is an existing folder, as in mv todo.txt Documents/, the file moves into it and keeps its name. cp follows the same rule.mkdir, cp or mv succeed they print nothing at all. Silence means success; only problems get a message.rm has no undoThere 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.
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.
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.
command -options arguments.pwd tells you which, ls shows what's there, cd moves you./ is absolute; anything else is relative to where you stand. . = here, .. = up one, ~ = home.mkdir and touch create; cat and echo print; cp copies; mv moves and renames.rm deletes for good. There's no Trash. Check where you are first.Tab to complete names and ↑ to repeat commands.Open a real terminal now and type pwd. That's it: you've started.