Skip to content
BENIBIX Learn

The Linux File Tree

Level 2 · Files, users and permissions

How Linux folders hang from one root, written as a slash. How to move around with pwd, cd and ls, and why some files are hidden.

Course contentsLesson 4 of 10

After this lesson you can

  • Read a file path from the root down
  • Move between folders with cd
  • List hidden files with ls -a

12 mincovers 7 glossary entries

Worth reading first: Environment Variables

How to find your way around the folders

On Linux, every file sits in one tree of folders that starts at the top folder, written as a single slash: /. There are no drive letters like C:. Your own folder is /home and your name, such as /home/emma, and the sign ~ is short for it. Three commands move you around: pwd, cd and ls.

A few folders under / are worth knowing. /etc holds settings. /var/log holds logs. /home holds each user's own folder. /root is the home of the root user, which is not the same as the top folder. /tmp holds files that are cleared out on a restart.

A file path is the list of folders down to a file, joined by slashes. /var/log/syslog starts at the top, so it means the same thing wherever you are. A path that does not start with a slash is read from the folder you are in now.

pwd prints the folder you are in. cd moves you to another one. cd /var/log goes straight there. cd .. goes up one level. cd on its own takes you home. ls lists what is in a folder, and ls -l adds the size, owner and date of each file.

A file whose name starts with a dot is hidden. ls does not show it, so a folder can look empty and still hold files. ls -a shows them. Settings live in hidden files, such as .bashrc, and keys for logging in to other machines live in a hidden folder called .ssh.

The two dots in cd .. are a real name, not a trick. Every folder holds two hidden entries: one dot for itself and two dots for the folder above. That is why ls -a always shows them first.

A common mistake is to run a command in the wrong folder. Delete commands act on the folder you are in. Before you change or delete anything, type pwd and check where you are. It costs one second and saves the wrong files.

console
$ pwd
/home/emma
$ cd /var/log
$ cd ..
$ pwd
/var
$ ls -a ~
.  ..  .bashrc  .ssh  notes.txt
Where am I, move, go up one, check again, then list your home folder with the hidden files.
Everything hangs from one slash at the top. Hidden files are there, just not listed by default.

Worked example

Emma looks for a server's settings

Emma logs in to a new server and lands in /home/emma. She needs the settings for its web program.

She types cd /etc/nginx and ls, and sees the file nginx.conf. Back home with cd, ls -a shows the .ssh folder she was told to look for.

The words for this lesson7

Check yourself

A folder looks empty with ls, but you were told a .ssh folder is in it. What do you type?

Finished this lesson?

Marking it complete also marks its 7 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.