Read

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

DirectoryHoldsExample
/bin, /sbinEssential programs; sbin ones are for administration./bin/ls, /sbin/reboot
/usrThe bulk of installed software, with its own bin, lib, share./usr/bin/less
/etcSystem configuration, as plain text files./etc/passwd, /etc/hosts
/home, /rootUsers' personal directories; root's is separate./home/ana, /root
/tmpScratch space, cleared at boot./tmp/build-3f2a
/varData that grows: logs, mail, caches./var/log
/devDevices, presented as files./dev/null, /dev/sda
/proc, /sysLive views of the kernel, invented on the fly./proc/cpuinfo
/libShared libraries programs need to run./lib/ld-uClibc.so.0
/mnt, /mediaConventional 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

CommandWhat it does
pwdPrint the absolute path of the working directory.
ls /List the top of the tree.
ls PATHList any directory without moving there.
ls -R PATHList a directory and everything below it.

Quiz

  1. What does `pwd` print?

    • Your password
    • The absolute path of the directory you are in
    • The list of files around you
  2. Where would you expect to find the system's configuration files?

    • `/etc`
    • `/tmp`
    • `/dev`
    • `/bin`
  3. How does Linux show a second disk?

    • As drive `D:`
    • Mounted on a directory somewhere in the single tree
    • As a second root `//`
  4. Your prompt says `bin%`. Which directory are you in?

    • `/bin`, always
    • Some directory named `bin`; run `pwd` to know which
    • Your home directory
  5. 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

  1. Print the absolute path of the directory you are in.

  2. 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.

  3. 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.