Basic

Moving around a filesystem

Navigation is the whole skill of knowing where you are. cd moves you, pwd tells you, and ls shows what you can move into. Getting lost is not a failure, it is a state you should notice and fix in one command.

What you will see

The path ending in a. Each ../ moves up one directory, and it is a name the shell resolves like any other.

About 1 min of reading

Try It

Navigate and confirm at each step.

1

Make a nested folder

mkdir -p a/b/c && cd a/b/c && pwd

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

What it prints
The full path ending in c. mkdir -p creates parents and does not fail if they exist.
2

Go back two levels

cd ../.. && pwd

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

What it prints
The path ending in a. Each ../ moves up one directory, and it is a name the shell resolves like any other.

Data Flow

A name resolves against the current directory.
1 Note the current directory
↓
2 Resolve the name against it
↓
3 Move or list
↓
4 Confirm the new position
Why this works
Spaces in names

cd My Docs fails because the shell splits at the space. Quote it, cd 'My Docs', or escape it. The failure is the shell doing its job correctly, which is why the fix is quoting rather than a different command.

Hidden files

A leading dot hides a file from a plain ls. Configuration lives there, which is why 'the file is not there' is often true and also the reason you are looking in the wrong place. Use ls -a when a dot file is suspected.

Examples

cd, pwd, ls as a habit

After every cd, run pwd or ls. Two seconds of work that removes the class of mistakes where you write a file in the wrong directory because you assumed you were somewhere else.

Relative versus absolute

cd build/tmp is relative to where you are; cd /home/blue/build is not. Absolute paths do not care where you were, which makes them the right choice in a script and often in a terminal too.

cd - and cd ~

cd - returns to the previous directory and cd ~ goes home. Both save the retyping that makes long paths error prone, and both are worth learning early because they change how much typing navigation costs.

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.

← What the shell actually does
Previous Lesson
What the shell actually does
Next Lesson
Creating and moving files
Creating and moving files →