Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Files, folders, and the command line

~30 min

Every Rust tool you'll use is started by typing a command, and every one of them works on files in a particular folder. In Chapter 1 you'll type hello.rs into a folder you make on this page, and the compiler will go looking for it there. So first, two things: how files and folders are named, and how to move around them by typing instead of clicking.

Files, folders, and paths

A file is one saved thing: a song, a photo, a page of writing. Its name usually ends with a dot and a few letters, like .jpg or .rs. That ending is called the extension. It tells you what kind of thing is inside. Rust code lives in files ending in .rs. The ending really is part of the name: notes.rs and notes.txt can sit side by side as two separate files.

A folder is a container for files. Folders can hold other folders, like boxes packed inside boxes. Some tools say directory instead of folder. It means the same thing.

A path is a file's address. It lists the folders you'd open, one after another, to reach the file. Sam's Windows laptop keeps a song at C:\Users\Sam\Music\song.mp3. Read it left to right: drive C, then the Users folder, then Sam's folder, then Music, and there's song.mp3. Windows puts a backslash (\) between the names. Macs and Linux use a forward slash (/), so on Sam's Mac the same kind of address reads /Users/sam/Music/song.mp3.

An address that starts from the outermost box, like those two (the drive C: on Windows, or the single / on a Mac or Linux), is called absolute. It works from anywhere, like a full postal address with the country on it. A shorter address like rust-course/hello.rs is relative. It's like "second door on the left": it only makes sense once you know where you're standing. The folder you're standing in right now is called the working directory. Two dots, .., mean "the folder one level up from here". A squiggle, ~ (called a tilde), means "my home folder": the folder that belongs to you when you log in.

You'll move around these folders from the command line. That means typing short instructions into a text window, instead of clicking icons. You'll open that window in the second half of this page.

A file is a named block of data stored on disk: a photo, a document, a Rust source file. The end of its name after the last dot, the extension (.rs, .txt, .exe), tells people and programs what kind of content to expect. The extension is part of the name, so notes.rs and notes.txt are two different files. A folder (also called a directory) holds files and other folders. The whole disk forms a tree with one top.

A path is the address of one file or folder: the folders you pass through from some starting point, joined by a separator. Windows uses \ and starts from a drive letter, as in C:\Users\Sam\rust-course\hello.rs. macOS and Linux use / and start from a single top folder written /, as in /Users/sam/rust-course/hello.rs on a Mac and /home/sam/rust-course/hello.rs on Linux. A path that starts at the top of the tree is absolute: it names the same place no matter where you are.

A relative path such as rust-course/hello.rs has no top of its own. It is read starting from the working directory, the folder a program (or a command you type) is currently "in". Three shorthands appear everywhere: . is the working directory itself, .. is the folder that contains it, and ~ is your home folder, the personal folder your account starts in. So the same relative path can name different files depending on the working directory, while an absolute path cannot. The command line means working with all of this by typing commands in a text window rather than using the mouse; the second half of this section opens one.

Works from anywhere, or depends where you are?

Sort each path: does it name the same place from any folder, or does it depend on the working directory?

Loading interactive…

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

What this task checks

Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.

The compiler says

A model answer

Correct answer

Also accepted:

Why

Why

A path that begins with a drive letter like C: or with a leading / starts from the top of the tree, so it works from anywhere. rust-course/hello.rs, hello.rs, .., and ../ch01 are all read from whatever folder you're in.

Worked example

Following a relative path

  1. 1

    Sam's working directory is /Users/sam. He asks for the file rust-course/hello.rs.

  2. 2

    A relative path starts from the working directory, so join the two with a /: /Users/sam + / + rust-course/hello.rs gives /Users/sam/rust-course/hello.rs. The file is there.

  3. 3

    Now he moves into rust-course and asks for rust-course/hello.rs again. Joined, that's /Users/sam/rust-course/rust-course/hello.rs. There's no rust-course folder inside rust-course, so the file isn't found.

    same words, new starting point, different answer

  4. 4

    From inside rust-course, the right relative path is just hello.rs. The absolute path /Users/sam/rust-course/hello.rs would have worked from both places.

Worked example

Going up with ..

  1. 1

    Sam is in /Users/sam/rust-course/ch01 and wants the folder ch00, which sits beside ch01 rather than inside it.

  2. 2

    .. means one folder up. From ch01, that's rust-course.

  3. 3

    So ../ch00 means: go up to rust-course, then down into ch00. It lands on /Users/sam/rust-course/ch00.

  4. 4

    ../.. goes up twice, to /Users/sam. On Windows the same trip is written ..\ch00, and PowerShell also accepts ../ch00.

Check your understanding (counts toward your progress)

What does ~ stand for in a path?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

One level up is ...

The working directory is ..

The top is / on macOS and Linux, or a drive letter on Windows.

Why

~ is shorthand for your home folder, the personal folder your account opens in.

It's the folder a new terminal starts in.

What is a path?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

A file name is just the last part of a path. The path adds the folders leading to it.

A path names a place, not a set of steps.

It's an address for one location, not a count.

Why

A path is an address: the folders you pass through, joined by / or \, ending at the file or folder you mean.

Think of a postal address.

report.rs and report.txt sit in the same folder. What's true?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Each is its own file. The different endings make them different names.

Their full names differ, so both can exist side by side.

Nothing is wrong. Different endings, different files.

Why

An extension is part of a file's name, so report.rs and report.txt are two separate files.

Sort each path: does it name the same place from anywhere, or does it depend on the working directory?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

What this task checks

Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.

The compiler says

A model answer

Why

Paths starting with a drive letter or a leading / start from the top, so they're absolute. The rest are read from the working directory.

Correct answer

Also accepted:

Why

Does the path start at the top, with a drive letter or a leading /?

Practice: Files, folders, and paths (5 problems · doesn’t affect your progress)

What makes a path relative?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Length has nothing to do with it. /a is absolute and short.

Both kinds of path can end in a file with an extension.

Windows uses backslashes in both absolute and relative paths.

Why

A relative path has no starting point of its own; it's read from the working directory. An absolute path starts at the top.

It's read starting from the working directory

Working directory /home/kai. Which file is rust-course/main.rs?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

That treats it as absolute. Start from the working directory instead.

That drops kai, which is part of the working directory.

That drops rust-course from the relative path.

Why

Join them: /home/kai + / + rust-course/main.rs.

/home/kai/rust-course/main.rs

Working directory /home/kai/rust-course/ch02. Where is ..?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

That's two levels up, ../...

That's ., the working directory.

That's the very top.

Why

.. is one level up: drop the last folder, ch02.

/home/kai/rust-course

From /home/kai/rust-course/ch02, which path reaches /home/kai/rust-course/ch01/notes.rs?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

That looks inside ch02, where there's no ch01.

Two levels up is /home/kai, which has no ch01.

~ is /home/kai, and ch01 isn't directly inside it.

Why

Up one to rust-course, then down into ch01.

../ch01/notes.rs

The same relative path ch01/notes.rs works from one folder and fails from another. What explains it?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Paths behave the same every time from the same folder.

Files stay put. Only your starting point changes.

Nothing is being written, so permissions don't come into it.

Why

A relative path is read from wherever you are. Change the working directory and it names a different place.

A relative path names different places depending on the working directory

Opening a terminal and running a command

A terminal is a window where you give your computer instructions by typing instead of clicking. Each instruction is called a command. You type it, press Enter, and the computer does it. Any reply is printed as text right below. Then a short marker called the prompt appears, and the terminal waits for your next command. On Windows the program that reads your commands is called PowerShell, and it runs inside an app called Windows Terminal. A Mac has an app simply called Terminal. Linux desktops have one too, usually with "Terminal" in its name. Details differ. The idea is the same everywhere.

A command reads like a short order: a verb first, then the thing it works on. Take mkdir rust-course: the verb is mkdir (short for "make directory", that is, make a folder) and rust-course is the name of the new folder. The extra words after the verb are called arguments.

A terminal is always standing in one folder, its working directory (the folder that relative addresses start from). When you first open a terminal, it's standing in your home folder. Four commands do nearly everything you'll need at first:

  • pwd asks "where am I?" It prints the full address of the folder you're in. The letters stand for "print working directory".
  • ls asks "what's in here?" It lists the files and folders.
  • mkdir makes a new folder. You stay where you were.
  • cd means "change directory". It moves you into another folder. cd .. moves you up one level. cd ~ takes you home.

One surprise: when a command works, it often prints nothing at all. An empty reply usually means success.

A terminal is a window for working with the computer by typing. It runs a shell, a program that reads one line of text you type (a command), runs it, and prints any result; then it shows a prompt and waits for the next line. The default shell is PowerShell on Windows (inside the Windows Terminal app), zsh on macOS, and usually bash on Linux. A command starts with its name; the words after it, separated by spaces, are arguments that say what to act on. In mkdir rust-course, mkdir is the command and rust-course is its one argument.

Four commands cover everything this course needs early on, and they work in all three shells. pwd prints the working directory as an absolute path. ls lists what's in the working directory. mkdir name makes a new folder there, without moving into it. cd path changes the working directory to path, absolute or relative; cd .. moves up one level and cd ~ goes home. A new terminal starts in your home folder. Many commands print nothing when they succeed, so an empty reply is normal.

Open a terminal now and make the folder you'll use in Chapter 1. Pick your operating system; the course remembers your choice.

Press the Windows key, type Terminal, and press Enter. Windows Terminal opens with a PowerShell prompt ending in >. Type these one at a time, pressing Enter after each:

cd ~
mkdir rust-course
cd rust-course
pwd

~ is your home folder, C:\Users\<your name>. PowerShell's pwd prints a small table with the heading Path, and the path under it should end in \rust-course. mkdir also prints a short table about the folder it made. That's PowerShell being chatty, not an error.

Press Cmd+Space, type Terminal, and press Enter. (It also lives in Applications, inside the Utilities folder.) The prompt ends in %. Type these one at a time, pressing Enter after each:

cd ~
mkdir rust-course
cd rust-course
pwd

~ is your home folder, /Users/<your name>, so pwd prints a path ending in /rust-course.

Open your applications menu and search for Terminal. On many desktops, including Ubuntu's, Ctrl+Alt+T opens one directly. The prompt usually ends in $. Type these one at a time, pressing Enter after each:

cd ~
mkdir rust-course
cd rust-course
pwd

~ is your home folder, /home/<your name>, so pwd prints a path ending in /rust-course.

On a Mac, the whole exchange looks like this. The lines starting with $ are what was typed (your prompt may look different); the others are the replies.

$ cd ~
$ mkdir rust-course
$ cd rust-course
$ pwd
/Users/sam/rust-course
$ ls
$

ls printed nothing because the new folder is empty. In Chapter 1 you'll save hello.rs here. Then ls will list it.

Set up a folder for Chapter 1

Put the commands in order: start from your home folder, make a folder called rust-course, go into it, make a folder called ch01 inside it, go into that, and check where you ended up.

Loading interactive…

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

What this task checks

Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.

The compiler says

A model answer

Correct answer

Also accepted:

Why

Why

Go home first, then make rust-course and step into it, so mkdir ch01 puts the new folder inside rust-course. Then enter ch01 and let pwd confirm the path ends in rust-course/ch01. cd ch01/rust-course has the folders backwards: there is no rust-course inside ch01.

Worked example

Where am I, and what's here?

  1. 1

    Open a fresh terminal and type pwd. It prints your home folder, because every new terminal starts there.

  2. 2

    Type cd rust-course. Nothing prints. That's success. Type pwd again: the path now ends in rust-course.

  3. 3

    Type mkdir ch01, then ls. The list shows ch01. But pwd still ends in rust-course, because mkdir made the folder without moving you into it.

    making a folder and entering it are two separate commands

  4. 4

    Type cd ch01 and you're inside. cd .. brings you back up to rust-course.

Worked example

When cd can't find the folder

  1. 1

    Priya opens a new terminal and types cd ch01 straight away. Instead of silence, she gets an error saying there's no such folder. The exact wording differs between PowerShell, zsh, and bash.

  2. 2

    ch01 is a relative path, so it's read from the working directory. A new terminal starts in the home folder, and ch01 isn't there. It's inside rust-course.

  3. 3

    Two fixes: cd rust-course first and then cd ch01, or give the path from home in one go with cd rust-course/ch01.

  4. 4

    When a command can't find something, type pwd and ls before anything else. They tell you where you really are and what's there.

Check your understanding (counts toward your progress)

Ana opens a new terminal and types cd ch01, but gets an error. ch01 is inside ~/rust-course. What works?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

The same relative path from the same folder fails the same way.

That would make a second, empty ch01 in the home folder instead of reaching the real one.

That climbs out of the home folder, away from rust-course.

Why

A new terminal is in the home folder. From there the route is rust-course/ch01, so cd rust-course/ch01 gets there in one step.

Relative paths are read from the home folder here. What's the route from home?

You open a new terminal. Which folder is it in?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

A new terminal doesn't remember where an old one was.

It starts lower down, in your own personal folder.

A terminal is always in some folder. It starts in your home folder.

Why

Every new terminal starts in your home folder. Type pwd to see its full address.

What does pwd print right after opening one?

Sort each command by the question it answers or the job it does.

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

What this task checks

Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.

The compiler says

A model answer

Why

pwd prints where you are, ls lists what's there, every cd moves you, and mkdir makes a folder without moving you.

Correct answer

Also accepted:

Why

Every cd moves you, whatever comes after it.

In mkdir rust-course, what is rust-course?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

The command is mkdir, the first word.

The prompt is the marker the terminal prints before you type.

It's the name of a folder that doesn't exist yet, so it can't be where you are.

Why

A command starts with its name, and the words after it are arguments. Here rust-course names the folder to make.

The first word is the verb. What's the next word?

Practice: Moving around in a terminal (5 problems · doesn’t affect your progress)

What does pwd do?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

That's mkdir.

That's cd ...

That's ls.

Why

pwd, print working directory, answers "where am I?" with an absolute path.

Prints the working directory's full path

After mkdir ch03, where are you?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

mkdir only makes the folder. cd ch03 would move you in.

mkdir doesn't move you anywhere.

mkdir doesn't move you up either.

Why

Making a folder and entering it are separate commands.

In the same folder as before

From anywhere, go home, go into rust-course, make ch03, go into it, and confirm.

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

What this task checks

Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.

The compiler says

A model answer

Why

Home, into rust-course, make ch03 there, enter it, and pwd confirms the path ends in rust-course/ch03.

Correct answer

Also accepted:

Why

A → E → B → D → C

cd rust-course just failed with a "no such" message. What's the best next move?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Same folder, same path, same failure.

Nothing is broken. You're probably just in a different folder than you think.

That might make an empty duplicate in the wrong place.

Why

When something isn't found, check where you are with pwd and what's there with ls before changing anything.

Type pwd and ls to see where you are and what's there

You're in ~/rust-course/ch03. Get to ~/rust-course/ch01 and list what's inside it. One line is a decoy.

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

What this task checks

Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.

The compiler says

A model answer

Why

../ch01 climbs to rust-course and goes down into ch01, then ls lists it. cd ch01 would look inside ch03.

Correct answer

Also accepted:

Why

ch01 sits beside ch03, not inside it.

C → B

Reading output and exit status

A command answers you in two ways. The first is the text it prints, which is its output. Error messages count as output too. They're there for a person to read.

The second answer is quieter. When any program finishes, it hands the computer one whole number, called its exit status (people also say exit code). It works like a thumbs-up or thumbs-down that the program gives as it leaves. The rule almost every program follows: 0 means "it worked", and any other number means "something went wrong". Which nonzero number came back can say what went wrong. Each program documents what its own numbers mean.

You don't see the exit status unless you ask for it. On a Mac or Linux, typing echo $? right after a command prints its number. ($? is the shell's name for "the last exit status"; echo just prints it.)

Windows PowerShell does it a little differently. There, $? prints True or False: did the last command work or not? A second name, $LASTEXITCODE, holds the actual number from the last program you ran.

Why have a number at all when there's a message? Because other programs read the number. A tool that builds your project checks for 0 before moving on to the next step. Messages are worded differently everywhere; the number means the same thing every time.

A command reports back in two ways. The first is output: text it prints for you to read, including error messages. The second is its exit status (also called an exit code): a whole number every program hands to the operating system when it ends. By a convention nearly every program follows, 0 means success and any other number means some kind of failure; the program's own documentation says what a particular nonzero value means. The exit status isn't printed, so you ask for it. In zsh and bash, echo $? prints the last command's exit status.

PowerShell splits the idea in two: $? is True or False for whether the last command succeeded, and $LASTEXITCODE holds the number the last program (rather than a built-in command such as cd) returned.

Scripts and build tools branch on the exit status rather than on the output, because the number means the same thing whatever the wording of the message.

In PowerShell, try a command that works, then one that fails, and ask about each one:

cd ~
$?
cd nosuchfolder
$?

The first $? prints True. The second cd prints a red error saying it can't find the path, and the $? after it prints False. When you run programs such as the Rust compiler in Chapter 1, $LASTEXITCODE will show the number each one returned.

Try a command that works, then one that fails, and ask about each:

$ cd ~
$ echo $?
0
$ cd nosuchfolder
cd: no such file or directory: nosuchfolder
$ echo $?
1

The first cd succeeded silently, and its exit status is 0. The second printed an error message and returned 1.

Try a command that works, then one that fails, and ask about each:

$ cd ~
$ echo $?
0
$ cd nosuchfolder
bash: cd: nosuchfolder: No such file or directory
$ echo $?
1

The first cd succeeded silently, and its exit status is 0. The second printed an error message and returned 1.

Did it work?

Sort each report: does it say the last command succeeded, or that it failed?

Loading interactive…

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

What this task checks

Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.

The compiler says

A model answer

Correct answer

Also accepted:

Why

Why

An exit status of 0 means success; any other number, 1 or 2 alike, means failure. PowerShell's $? turns that into True or False. An empty reply with status 0 is the normal look of a command that worked.

Worked example

Silence or failure?

  1. 1

    Sam types mkdir ch02 and gets no reply at all. Did it work?

  2. 2

    No news isn't proof. He types echo $? and sees 0. Success: an empty reply plus status 0 is how a quiet command says "done".

  3. 3

    He types mkdir ch02 a second time. Now there's a message saying the folder already exists, and echo $? prints 1.

    the message is for Sam; the number is for any program watching

  4. 4

    The message says what went wrong in words. The 1 says the same thing as a number, which another program could check without reading the words.

Where this goes next

Chapter 1 §2 has you open this same terminal to install Rust. You then type two commands that print version numbers, to prove the install worked. Chapter 1 §3 runs the compiler on hello.rs from inside the rust-course folder you just made. That works only because hello.rs is a relative path, read from the working directory. Chapter 1 §4 makes your first full project in a folder of its own and builds it from there. The exit status matters from the first build on. A build that fails returns a nonzero status. That's how editors and automated checkers know to stop.

Check your understanding (counts toward your progress)

Sam runs a command, then pwd, then echo $?, which prints 0. What does that 0 tell him about the first command?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

$? only remembers the most recent command, and that was pwd.

It can't say, because pwd replaced the first command's status.

The 0 means the last command worked.

Why

$? holds only the last command's status. To learn about the first command, ask straight after it.

Which command ran right before echo $??

In PowerShell, what's the difference between $? and $LASTEXITCODE?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

They differ in kind: one is a yes-or-no, the other a number.

That's reversed.

It holds a single program's status, not a running total.

Why

PowerShell's $? answers "did the last command work?" with True or False. $LASTEXITCODE holds the actual number from the last program, such as the Rust compiler.

One of them prints a word, not a number.

A command's output includes which of these?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

The exit status is separate and isn't printed unless you ask.

Files it makes are saved on disk, not printed.

Many commands print nothing when they work, but plenty print text.

Why

Output is the text a command prints for you to read, including error messages. The exit status is its separate, quiet report.

Practice: Output and exit status (4 problems · doesn’t affect your progress)

Which exit status means success?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

1 is the most common failure code.

Nonzero means something went wrong.

Large numbers are failures too.

Why

By convention 0 is success and every other number is failure.

0

cd projects prints nothing. echo $? prints 0. Did it work?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

cd is quiet when it works. The 0 confirms it.

The status already tells you.

An empty folder is still a place you can be in.

Why

A silent command with status 0 succeeded.

Yes: no reply plus status 0 is success

In PowerShell, cd nosuchfolder prints a red error. What does $? print next?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

The command failed, so the answer to "did it work?" is no.

PowerShell's $? is True or False, not a number.

It reports success or failure, not what you typed.

Why

PowerShell's $? says whether the last command worked. A failed cd gives False.

False

A tool that builds projects runs the compiler and sees exit status 1. What should it do?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

A failed compile made no executable, so there's nothing new to run.

The number alone already says it failed.

Exit statuses aren't counts. Nonzero means failure.

Why

A nonzero status means failure, and a failed compile writes no executable. The tool stops and shows you the error.

Stop: the build failed, so there's nothing new to run

Feeling good about this section?

Take the section quiz

Every answer gets a full explanation at the end.

Sign in to save highlights

Insert an equation

  • No matches.