Guías

How to use the terminal

The mental models first, the commands second. Enough to stop being afraid of a black window.

Actualizada

The terminal is a text conversation with your computer. You type a sentence, it does the thing, it tells you what happened. That's the whole idea. Everything that makes it feel hostile — the blinking block, the lack of buttons, the silence when a command works — comes from that one difference: there is nothing to click, so there is nothing to discover by looking.

Which means the way in isn't memorising commands. It's learning to read a command you've never seen before and guess what it does. Three models get you most of the way.

A command is a sentence

ls-la/Documents
ls (Cmd)
The action to perform. Here: list.
-la (Flags)
Options that change how it acts.
/Documents (Arg)
What the action is done to.
Every command is a sentence: a verb, some adverbs, and an object.

Once you see that shape, an unfamiliar command stops being noise. git commit -m "fix" is a verb, an adverb and an object, exactly like ls -la /Documents. You may not know what it does, but you know which part is the action and which part is the target — and that's usually enough to look up the rest.

Flags almost always start with a dash. One dash for short ones that can be bundled — -la is -l and -a together — and two dashes for long ones, like --help. When you're stuck, --help after almost any command is the fastest thing you can type.

Paths are directions

A path tells the computer where something is. There are only two kinds.

An absolute path is the full postal address, starting from the very top: /Users/you/Documents/project. It works from anywhere, because it doesn't depend on where you're standing.

A relative path is directions from where you are right now: project means *the project folder inside this one*. Shorter to type, but it only makes sense in context.

Three shorthands do most of the work. ~ is your home folder. . is right here. .. is one level up — and you can chain it, so ../.. goes up two. That's the entire pathing system.

The commands worth knowing

You need about a dozen. Search this list rather than reading it — the point is to come back to it, not to memorise it.

12 of 12 commands shown

  • pwdnavigate

    Tells you which folder you are currently inside.

    pwd
    /Users/you/Desktop
  • lsnavigate

    Lists what's in the current folder. Like turning the lights on.

    ls
    Documents  Downloads  Music
  • cdnavigate

    Walks into a folder, or back out of one.

    cd Documents
    cd ..
  • mkdircreate

    Creates a new, empty folder.

    mkdir my_new_project
  • touchcreate

    Creates a new, blank file.

    touch index.html
  • cpcreate

    Copies a file. Add -r to copy a whole folder.

    cp notes.txt backup.txt
    cp -r site/ site-backup/
  • mvmove

    Moves a file — and it's how you rename one, too.

    mv typo.txt fixed.txt
  • catread

    Prints a whole file to the screen. Best for short files.

    cat notes.txt
  • lessread

    Reads a long file one screen at a time. Press q to quit.

    less server.log
  • grepsearch

    Finds the lines in a file that contain something.

    grep "error" server.log
  • rmdirdelete

    Removes a folder — but only if it is already empty.

    rmdir empty_folder
  • rmWarning

    Deletes a file permanently. It does not go to the Trash.

    rm useless_file.txt

Notice which one is marked. rm deletes permanently: there is no Trash, no undo, and no confirmation unless you ask for one. This is the single sharpest edge in the terminal, and it's worth a moment of respect every time you type it.

The keys that make it fast

This is the part that separates people who tolerate the terminal from people who like it. None of it is about knowing more commands.

The six that save the most time. Tab and Ctrl+R are the two worth building a habit around.
KeysSuperpower
TabAuto-completeType the first few letters of a name and press it. The shell fills in the rest.
Time travelWalks back and forward through commands you've already run.
CtrlRSearch historyType any part of an old command and it finds it. Press it again to keep looking.
CtrlCEmergency stopKills whatever is running right now. The one to remember when something runs away.
CtrlLClear the screenWipes the clutter without losing any history.
CtrlAEJump the lineSends the cursor to the start (A) or the end (E) of what you're typing.

Tab is the one to build a habit around first. It completes file names, so you stop typing them and you stop mistyping them. Ctrl + R is the second: it searches everything you've ever run, which means the hard command you figured out last month is four keystrokes away instead of gone.

Check yourself

Type cd ../..Every .. means *the folder above this one*. The slash chains them, so ../.. is two hops up in one move.

Press Ctrl + CThat sends an interrupt signal to whatever is running. Closing the window would work too, but this keeps your session and your history.

Type rm dr and press TabLet the shell do the typing. As long as dr matches only one file, Tab completes the rest — and with rm, a typo is the expensive kind of mistake.

The Trash can be emptied later. rm is already empty.There is no undo and no holding area. This is why the rm card is the only one on this page with a warning on it.

That's the foundation. The next thing worth learning is how to keep work running on a machine after you disconnect from it — which is tmux, and it's the guide that made this one necessary.