Basic

What the shell actually does

I typed a command and a program ran. Between my words and that program sits the shell, and it does work I did not ask for: it expands wildcards, splits words, runs redirects, and picks which file a name refers to. Most shell confusion is confusion about that work, not about the program.

What you will see

One line per entry, with . and .. present. The -a flag reveals the entries the default listing hides.

About 2 min of reading

Try It

See the shell's own state.

1

Where am I

pwd

Before you run it, say out loud what it will print. Then open the answer.

What it prints
An absolute path - the directory every bare name will be resolved against.
2

What is in it

ls -la

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line per entry, with . and .. present. The -a flag reveals the entries the default listing hides.

Data Flow

A line of text becomes a program call.
1 Read the line you typed
↓
2 Expand globs and split words
↓
3 Set up redirects
↓
4 Find the program and run it
Why this works
Type, then look

Run the shortest command that shows the effect, before the one that makes it. ls before rm, cat before writing. The shell gives feedback fast enough that checking is cheaper than thinking ahead and being wrong.

Learn the failure messages

No such file or directory means the name is wrong. Permission denied means the name is right and you cannot run or read it. Not a command means the shell did not find a program by that name. Three different problems, three different fixes.

Examples

The shell reads, then runs

The shell parses the line first: it expands globs, splits into words, sets up redirects. Then it finds the program and runs it with the arguments it decided on. The program never sees your original line.

Names are paths

A bare word is a path relative to the current directory. That is why the same command works in one folder and fails in another, and why an absolute path is the fix rather than more typing.

The shell has state

Current directory, environment variables, and exit status persist between commands. That state is why a session that worked once may not work again, and why a script sets its own state at the top.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

Next Lesson
Moving around a filesystem
Moving around a filesystem →