Module 1 · First steps in the terminal
Where am I? pwd and the filesystem tree
One tree, one root, no drive letters: how Linux arranges every file under /, what the top-level directories are for, and how pwd tells you where you stand.
What you will learn
- Print the working directory with `pwd`.
- Describe the single-rooted tree and the role of `/`.
- Recognise the standard top-level directories and what lives in them.
Every shell has a working directory: the place in the filesystem where it currently stands, and where relative names are looked up. The prompt hints at it, but only with the last component. pwd — *print working directory* — gives the whole truth.
~% pwd
/root
~% cd /usr/bin
bin% pwd
/usr/bin
Notice the second prompt: bin%. There are several directories called bin on the system, so the prompt alone is ambiguous; pwd says *which* bin. Make a habit of running it whenever you are unsure. It costs nothing and it prevents the classic mistake of deleting the right file in the wrong directory.
One tree, one root
Linux has no C: or D:. There is exactly one tree, and its top is a directory with the shortest name possible: /, called the root of the filesystem (an unfortunate clash with the user called root; they are unrelated). Every file on the machine has a path that starts at / and walks down, one directory per slash: /usr/bin/less means "in /, enter usr, enter bin, find less". Extra disks, USB sticks and network shares do not get letters; they are mounted onto a directory somewhere in the tree and appear as part of it. Module 7 covers how.
~% ls /
bin etc lib media opt root sbin tmp var
dev init lib32 mnt proc run sys usr
What the top-level directories are for
| Directory | Holds | Example |
|---|---|---|
/bin, /sbin | Essential programs; sbin ones are for administration. | /bin/ls, /sbin/reboot |
/usr | The bulk of installed software, with its own bin, lib, share. | /usr/bin/less |
/etc | System configuration, as plain text files. | /etc/passwd, /etc/hosts |
/home, /root | Users' personal directories; root's is separate. | /home/ana, /root |
/tmp | Scratch space, cleared at boot. | /tmp/build-3f2a |
/var | Data that grows: logs, mail, caches. | /var/log |
/dev | Devices, presented as files. | /dev/null, /dev/sda |
/proc, /sys | Live views of the kernel, invented on the fly. | /proc/cpuinfo |
/lib | Shared libraries programs need to run. | /lib/ld-uClibc.so.0 |
/mnt, /media | Conventional places to mount other disks. | /media/usb |
You do not need to memorise this table; you will absorb it by walking around. Two things are worth fixing now. First, configuration lives in /etc as text you can read with cat. Second, your own files belong under your home directory. As root here, that is /root, and the course stages all its exercises under /root/lab.
Looking without moving
ls takes a path, so you can inspect any directory from where you stand: ls /etc, ls /root/lab. Add -R and it recurses, listing each subdirectory in turn with a header such as ./docs:. It is the quickest way to see a whole small tree at once, since this machine has no tree command. Lesson 5 teaches cd, the command that actually moves you.
Commands in this lesson
| Command | What it does |
|---|---|
pwd | Print the absolute path of the working directory. |
ls / | List the top of the tree. |
ls PATH | List any directory without moving there. |
ls -R PATH | List a directory and everything below it. |
Quiz
What does `pwd` print?
- Your password
- The absolute path of the directory you are in
- The list of files around you
Where would you expect to find the system's configuration files?
- `/etc`
- `/tmp`
- `/dev`
- `/bin`
How does Linux show a second disk?
- As drive `D:`
- Mounted on a directory somewhere in the single tree
- As a second root `//`
Your prompt says `bin%`. Which directory are you in?
- `/bin`, always
- Some directory named `bin`; run `pwd` to know which
- Your home directory
What is special about `/proc`?
- It stores users' documents
- Its files are generated live by the kernel, not stored on disk
- It is where programs are installed
Practice
Print the absolute path of the directory you are in.
Somewhere under /root/lab/l3/tree there is a file called `goal.txt`. Use `ls -R /root/lab/l3/tree` to find which directory holds it, then create an empty file called `done` in that same directory.
List the top-level directories of the filesystem: the contents of the root directory.
Open this lesson in the app to do the tasks in a real Linux machine and have them checked.