Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · navigation

cd

going somewhere else

cd moves the shell to another directory. It takes an absolute path, which starts at the root, or a relative one, which starts from where you are. It prints nothing when it works — silence is success, as with most Unix commands.

A path that begins with a slash means the same thing everywhere. One that does not depends on where you are standing.

Changes
Working directory
for this shell only
No argument
Goes home
the same as cd ~
Up one level
cd ..
two dots are the parent
Back again
cd -
the previous directory

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashshell builtin
$ cd /var/log
$ pwd
1/var/log
2$ cd nginx
3$ cd ..
$ cd -
4/var/log/nginx
5$ cd
$ pwd
/home/user
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
An absolute path works from anywhere

/var/log begins at the root, so it names the same directory no matter where the shell was.

2
A relative path starts from here

No leading slash: "nginx" is looked for inside the current directory, giving /var/log/nginx.

3
Two dots are the parent

Every directory contains an entry called ".." that points one level up. This returns to /var/log.

4
A dash is "where I just was"

cd - swaps back to the previous directory and prints it, so you can flip between two places.

5
Nothing at all means home

cd with no argument goes to your home directory. The tilde, ~, is shorthand for the same place.

Switches

A switch changes how the command behaves. These are the ones used day to day; man cd lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-
Go back to the directory you were in before the last cd.
..
Go up one level, to the parent directory.
~
Go to your home directory. Plain cd does the same.
-P
Follow the physical path: resolve symbolic links instead of keeping them in the path.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

cd ~/projects

The tilde expands to your home directory, so this works from anywhere.

cd ../..

Up two levels in one step.

cd "My Documents"

Quote a name that contains spaces, or the shell reads it as two arguments.

pushd /etc && popd

Remembers where you were on a stack and returns to it — handy when hopping between several places.

In cybersecurity

To enter a directory you need the execute bit on it, not the read bit — a detail that explains most "Permission denied" answers from cd.

x on a directory means "may enter"

Without it nobody can cd in or reach anything beneath, whatever the files' own permissions say.

Check that cd worked

In a script, "cd build; rm -rf *" deletes the wrong directory if cd failed. Write "cd build && …" or stop on error.

Path traversal

The same ".." that takes you up a level is how a careless web application is talked into reading files outside its folder.

Filed under

Navigation

Read alongside