Skip to content

Root, home, and the current directory

Module
Navigating the Filesystem
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (lab system, Ubuntu Desktop package set), GNU Bash 5.2.21; Ubuntu 24.04.4 LTS course VM (VirtualBox 7.2.18)
On this page

You open a new terminal to read your to-do list from lesson B04.1, and you type the command you have used many times:

Screen
learner@rootvolt:~$ cat todo.txt
cat: todo.txt: No such file or directory

The file exists, and the command is right. What is wrong is the place: a terminal always works in one directory, and this one is looking in the wrong one. Every lesson of module B04 told you to run cd ~/lab in a new terminal, and never said why.

By the end of this lesson, you can say which directory you are in, move one directory down and one up, and explain the four names /, ~, . and ... You can also tell apart three things that are all called root.

This time, do not run cd ~/lab first. Open a new terminal with Ctrl+Alt+T, as in lesson B03.2, and start there.

In the new terminal, run:

Terminal window
pwd
Output
/home/learner

pwd stands for “print working directory”. It prints the current directory: the directory your shell works in. Another name for it is the working directory, as in help cd in lesson B04.3: “Change the shell working directory”. Each terminal window runs its own Bash (lesson B03.2), with its own current directory, and a new one starts in /home/learner.

This explains the opening. A program looks for a name such as todo.txt in the current directory. todo.txt is not in /home/learner. It is in lab, one level further down.

/home/learner is a chain of names. Read it from the left:

  • The / at the very start is the root directory: the top of the file tree, which holds all other directories. Lesson B02.3 said that the installer puts your system in /.
  • home is a directory inside /.
  • learner is a directory inside home.

The other / characters only separate the names. Every directory except / is inside another directory, and following them upward always ends at /.

The command ls / lists the root directory. On the course VM, it prints:

Output (course VM)
bin home mnt sbin.usr-is-merged usr
bin.usr-is-merged lib opt snap var
boot lib64 proc srv
cdrom lib.usr-is-merged root swap.img
dev lost+found run sys
etc media sbin tmp

Find home in the list, then list it:

Terminal window
ls /home
Output (course VM)
learner

/home holds the home directories of the regular users; lesson B02.3 created one. Your ls / can differ slightly, for example in swap.img, which depends on how the system was installed. Lesson B05.4 explains the main directories.

/home/learner is your home directory. The prompt shows it as ~, and Files shows it as Home (lesson B03.1). When a word is ~ or starts with ~/, Bash replaces the ~ with the full name of your home directory before it runs the command. So cd ~/lab and cd /home/learner/lab mean the same thing.

If you chose another user name in lesson B02.3, your home directory is /home/ followed by that name.

cd means “change directory”. Give it the name of a directory inside the current one:

Terminal window
cd lab

cd prints nothing. Look at the prompt instead: it now ends in ~/lab$. Run the command from the opening again:

Terminal window
cat todo.txt
Output
Install Ubuntu
Verify the ISO checksum
Take a snapshot

The command did not change. The place did.

A directory inside another one is its child (lesson B04.3 called it a subdirectory), and the directory that holds it is its parent. So lab is a child of /home/learner, and /home/learner is the parent of lab.

Go one level further down, and check where you are:

Terminal window
cd Documents
pwd
Output
/home/learner/lab/Documents

The prompt says ~/lab/Documents, and pwd gives the same directory with its full name, starting at /.

To go back to the parent, give cd the name .., two dots:

Terminal window
cd ..

The prompt ends in ~/lab$ again. .. means the parent of the current directory, so you do not need to know the parent’s name.

The replay below shows this walk from a new terminal, with the current directory marked in the Files panel. Above lab, the panel draws only /, home, and your home directory.

One directory down, one directory up
learner@rootvolt:~$ pwd/home/learnerlearner@rootvolt:~$ cd lablearner@rootvolt:~/lab$ cd Documentslearner@rootvolt:~/lab/Documents$ pwd/home/learner/lab/Documentslearner@rootvolt:~/lab/Documents$ cd ..learner@rootvolt:~/lab$ 

Files Other folders in / are not shown

  • /
    • home/
      • learner/~
        • lab/cwdargument
          • Documents/
            • notes.txt-rw-r--r--
            • report.txt-rw-r--r--
          • .draft.txthidden-rw-r--r--
          • projects/
          • todo.txt-rw-r--r--

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS (lab system, Ubuntu Desktop package set), GNU Bash 5.2.21. cd lab and cd Documents each move one level down; cd .. moves back up to the parent, ~/lab.
Steps (13)
  1. Type pwd — Where am I? A new terminal starts in your home directory
  2. Press Enter
  3. Output: /home/learner
  4. Type cd lab — Move down into the child directory lab
  5. Press Enter
  6. Type cd Documents — One more level down
  7. Press Enter
  8. Type pwd — The full name of the current directory
  9. Press Enter
  10. Output: /home/learner/lab/Documents
  11. Type cd .. — .. is the parent: one level up
  12. Press Enter
  13. cd with a child's name moves down one level; cd .. moves up to the parent.

In words: pwd prints /home/learner. cd lab moves the marker from your home directory down to lab, and cd Documents down to Documents. pwd prints /home/learner/lab/Documents. cd .. moves the marker back up to lab.

In lesson B04.1, ls -a showed two names you never created, . and ... Go into Documents and look again:

Terminal window
cd Documents
ls -a
Output
. .. notes.txt report.txt

Every directory has these two entries. .. is its parent, the name you gave cd above. . is the directory itself. Compare:

You run in ~/lab/Documents Output Lists
ls . notes.txt report.txt Documents itself, the same as ls
ls .. Documents projects todo.txt Its parent, lab

So cd . moves you nowhere: you are already there.

You met .. once before: in lesson B02.2, ../SHA256SUMS named the file SHA256SUMS in the parent of the altered folder. Lesson B05.2 explains names like this.

You are in ~/lab/Documents. Run cd .. once to get back to ~/lab.

Now guess. From ~/lab, you run cd .. four times in a row. Where are you after the third time? And what does the fourth one do, when there may be nothing above?

Run it, then compare with your guess
Screen
learner@rootvolt:~/lab$ cd ..
learner@rootvolt:~$ cd ..
learner@rootvolt:/home$ cd ..
learner@rootvolt:/$ cd ..
learner@rootvolt:/$ pwd
/

The first cd .. reaches your home directory, the second /home, and the third /. Outside your home directory, the prompt shows the full name.

The fourth cd .. gives no error and does not move you. / has no parent, so in /, the name .. means / itself.

To go home from anywhere, run cd ~. cd with no argument does the same: it moves you to your home directory.

Climbing from ~/lab to / and back home
learner@rootvolt:~/lab$ cd ..learner@rootvolt:~$ cd ..learner@rootvolt:/home$ cd ..learner@rootvolt:/$ cd ..learner@rootvolt:/$ pwd/learner@rootvolt:/$ cd ~learner@rootvolt:~$ 

Files Other folders in / are not shown

  • /
    • home/
      • learner/~cwd
        • lab/
          • Documents/
            • notes.txt-rw-r--r--
            • report.txt-rw-r--r--
          • .draft.txthidden-rw-r--r--
          • projects/
          • todo.txt-rw-r--r--

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS (lab system, Ubuntu Desktop package set), GNU Bash 5.2.21. Each cd .. moves one level up until /, where it stops; cd ~ goes straight back to the home directory.
Steps (14)
  1. Type cd .. — From ~/lab up to your home directory
  2. Press Enter
  3. Type cd .. — Up to /home
  4. Press Enter
  5. Type cd .. — Up to /, the root directory
  6. Press Enter
  7. Type cd .. — At / there is no level above
  8. Press Enter
  9. Type pwd — Check where you are
  10. Press Enter
  11. Output: /
  12. Type cd ~ — ~ takes you home from anywhere
  13. Press Enter
  14. Each cd .. goes up one level until /, the top. cd ~ goes straight home.

In words: from ~/lab, three cd .. commands move the marker to your home directory, /home, and /. A fourth leaves it on /, where pwd prints /. cd ~ moves it straight back home.

You have now met three things called root:

Name What it is Where you met it
/ The root directory, the top of the file tree This lesson; lesson B02.3
root The administrator account Lesson B03.3
/root The root account’s home directory Lesson B03.3

/root is not /: it is one directory inside /, next to home, as the ls / output above shows. And root’s home directory is not inside /home, which holds only learner.

The course VM can also show who owns each directory. The option -d makes ls describe a directory itself instead of listing what is in it:

Terminal window
ls -ld / /root /home /home/learner
Output (course VM)
drwxr-xr-x 23 root root 4096 Nov 2 00:28 /
drwxr-xr-x 3 root root 4096 Nov 2 00:28 /home
drwxr-x--- 15 learner learner 4096 Nov 5 06:57 /home/learner
drwx------ 5 root root 4096 Nov 2 00:53 /root

The third column names the account that owns each directory: root owns /, /home, and /root, and learner owns its home directory. Module B11 explains the other columns. Your dates and numbers will differ.

Read each message in three parts, as in lesson B04.4: who is speaking, which word it names, and what went wrong.

No space after cd.

Screen
learner@rootvolt:~/lab$ cd..
cd..: command not found

No program name speaks first. The word is cd.., and it is not found. Without the space, Bash reads one word and looks for a command called cd.., as with ls-l in lesson B04.1. Type cd .., with a space.

A child of another directory.

Screen
learner@rootvolt:~/lab/Documents$ cd projects
bash: cd: projects: No such file or directory

Bash speaks for cd, which is part of Bash (lesson B04.4). The word is projects, and the message says there is no such directory. Yet you created projects in lesson B04.1: it is a child of lab, not of Documents, and cd looks for the name in the current directory only. Go up with cd .. first, then run cd projects.

On the course VM, the same mistake can give no error at all. Your home directory has its own Documents, which Files showed in lesson B03.1, separate from ~/lab/Documents. So in a new terminal, cd Documents moves you into that other directory. Read the prompt: the lab’s directory is ~/lab/Documents.

Root’s home directory.

Screen
learner@rootvolt:~/lab/projects$ cd /root
bash: cd: /root: Permission denied
learner@rootvolt:~/lab/projects$ pwd
/home/learner/lab/projects

Bash speaks for cd again, and the word is /root. This time the directory exists, and Permission denied says that your account may not enter it: it is the root account’s home, as in lesson B03.3. A cd that fails does not move you, as pwd shows.

Goal: Reach a directory the lesson did not visit, look at its parent, and climb partway up.

  1. Open a new terminal. Move into ~/lab/projects one level at a time, and check where you are.
  2. Without leaving projects, list what is in its parent.
  3. Using only cd .., go up until you are in /home. Count how many times you need it, and check where you are.
  4. Go back to your home directory with a two-letter command.

Expected: pwd prints /home/learner/lab/projects, then /home. The listing in step 2 shows Documents projects todo.txt. At the end, the prompt is learner@rootvolt:~$, and pwd prints /home/learner.

Hint

Start with lab. Every directory has an entry for its parent, and ls can list that entry.

Solution
Screen
learner@rootvolt:~$ cd lab
learner@rootvolt:~/lab$ cd projects
learner@rootvolt:~/lab/projects$ pwd
/home/learner/lab/projects
learner@rootvolt:~/lab/projects$ ls ..
Documents projects todo.txt
learner@rootvolt:~/lab/projects$ cd ..
learner@rootvolt:~/lab$ cd ..
learner@rootvolt:~$ cd ..
learner@rootvolt:/home$ pwd
/home
learner@rootvolt:/home$ cd
learner@rootvolt:~$ pwd
/home/learner

You need cd .. three times: to lab, to your home directory, and to /home. The two-letter command is cd with no argument; cd ~ works as well.

  • Every shell works in one current directory. pwd prints its full name, and the prompt shows it too, with ~ for your home directory.
  • / is the root directory, the top of the file tree. /home/learner is learner inside home inside /.
  • cd with the name of a child moves one level down. cd .. moves to the parent. In /, .. is / itself. cd ~ or cd takes you home.
  • Every directory has two entries: . for itself and .. for its parent.
  • / is the root directory, root is the administrator account, and /root is that account’s home directory: three different things.

Next, Absolute and relative paths (B05.2) shows how to name a directory from anywhere in the tree, so cd can reach it in one step.

  • GNU Bash Reference Manual: Bourne Shell Builtins, the entries for cd and pwd. On your system, help cd and help pwd print short versions.
  • GNU Bash Reference Manual: Tilde Expansion, how Bash replaces ~ with your home directory.
  • man 7 hier on your system, or the Ubuntu 24.04 hier(7) page online: the layout of the file tree.
  • Filesystem Hierarchy Standard 3.0: The Root Filesystem, with sections on /home and /root.
  • man ls for the -a and -d options, or the Ubuntu 24.04 ls(1) page online.