Course page
Log in

You are watching a free preview. Enroll to open all 25 lessons, track progress and ask the course tutor.

Enroll now

Section 1: First steps in the shell

Finding your way around the file system

Article 11 min Lesson 2 of 25 Preview

Linux arranges everything in a single tree that starts at /, called root. There are no drive letters. Extra disks and USB sticks appear as folders somewhere inside the tree.

Important directories

  • /home: personal folders for users, such as /home/sofia.
  • /root: the home directory of the root user.
  • /etc: system wide configuration files.
  • /var: changing data, especially /var/log for logs.
  • /usr: installed programs and libraries, such as /usr/bin.
  • /tmp: temporary files, often cleared on reboot.
  • /opt: optional, self contained software packages.
  • /dev, /proc, /sys: special files representing devices, processes and kernel information.

Where am I, and what is here?

pwd            # print working directory
ls             # list files
ls -la         # long format, including hidden files
ls -lh /var/log   # human readable sizes

Files whose names start with a dot, such as .bashrc, are hidden. ls -a shows them.

Moving around

cd /var/log    # absolute path: starts from /
cd ..          # up one level
cd nginx       # relative path: from where you are
cd ~           # home directory (plain cd does the same)
cd -           # back to the previous directory

An absolute path starts with / and works from anywhere. A relative path starts from your current directory. . means the current directory and .. means the parent.

Reading the long listing

-rw-r--r-- 1 sofia staff  2048 Mar  5 10:12 notes.txt
drwxr-xr-x 3 sofia staff    96 Mar  5 09:40 projects

From left to right: type and permissions (d for directory, - for file), link count, owner, group, size in bytes, modification time and name. We decode the permission letters in section four.

Finding files

find ~/projects -name "*.md"
find /var/log -type f -mtime -1      # files modified in the last day

find walks the tree and matches on name, type, size, age and more. It is one of the most useful commands you will learn.

Exercise

Starting from your home directory, visit /etc, list it with ls -l, find the file that contains your system's host name (hostname), go back with cd -, and use find to list every .conf file directly inside /etc.

← → switch lessons