Chapter 2: Directories and files

The root directory

face Robert Craven Josiah Wang

Perhaps you now have itchy feet! Having seen some of the Linux filesystem, let’s wander around it a bit. Type the following.

username@MACHINE:~$ cd /
username@MACHINE:/$ ls

/ is the root directory. We just changed the working directory to it using cd /, and then listed its contents using ls.

Notice that the prompt changed when we moved directories.

Root directory

/ is the root of the Linux filesystem. It contains various directories with different sorts of system files important for the operating system, programs, files to help interaction with hardware, temporary storage space, and so on.

The full name of any file or directory starts with / and moves through nested sub-directories, separated by /.

Your home directory, /homes/username, is in the directory /homes, and /homes is itself in the root directory, /.

Exercise 3

  1. Set the working directory to be /usr/bin.
  2. List the contents of this directory in one column.

I’m going back home

To return to your home directory, type the following

username@MACHINE:/usr/bin$ cd

A bare cd by itself always returns you to ~.

Now type the following:

username@MACHINE:~$ cd -

What do you think cd - does? Try typing it again to confirm.