Unit 1: The shell and the filesystem · Lesson 2 of 5 · 18 min

Moving around the tree

Use absolute and relative paths to find the server inventory and read it.

mission

You are
You are building a picture of the network web01 lives in.
Situation
The handover says the server inventory sits somewhere under /srv. You need the database server's address before you touch any config.
Goal
Walk the directory tree to the inventory and read the server records.
Hand in
The IP of db01 and the subnet of the backup network.

The directories you will use in this course

Click a directory to open it$ tree /
/
├──
├──

Pick anything to read what it holds.

Open a directory to see what it is for.
01

Turn any path into an absolute one

realpath resolves ., .. and ~ so you know exactly where a path points before you act on it.

learner@root-lab
realpath ./README.txt
/home/learner/README.txt
realpath /srv/inventory/servers/..
/srv/inventory
realpath ~/../..
/

you should see .. goes up one level, so two of them from your home land on /.

02

Map the inventory

learner@root-lab
cd /srv/inventory
tree
.
├── network
│   ├── firewall.nft
│   └── vlans.txt
└── servers
    ├── backup01.txt
    ├── db01.txt
    └── web01.txt

3 directories, 5 files

you should see Two folders. tree draws what ls would take several commands to show.

defender tip On a server you have never seen, tree -L 2 /srv /opt gives a quick map of what admins added.

03

Read the records with relative paths

learner@root-lab
cat servers/web01.txt
hostname: web01
role: public website
ip: 10.20.0.11
os: Ubuntu 24.04
cat network/vlans.txt
10  office     10.10.0.0/24
20  servers    10.20.0.0/24
30  backups    10.30.0.0/24

you should see No leading slash: both paths start from /srv/inventory, where you are standing.

Moving around

CommandWhat it does
pwdWhere am I
cd /srv/inventoryGo somewhere by absolute path
cd serversGo somewhere relative to here
cd ..Up one level
cdBack home
cd -Back to the previous directory

What a defender takes away

  1. 1Absolute paths start with / and work from anywhere.
  2. 2Relative paths start from where you stand.
  3. 3Check a path with realpath before you change anything there.

Questions

0 of 3 solved

Answer each one from what you find on your lab machine.

  1. Show hint

    Read servers/db01.txt in the inventory.

  2. Show hint

    network/vlans.txt

  3. Show hint

    ls or tree the directory.