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
/
├──
├──
├──
├──
├──
├──
└──
Pick anything to read what it holds.
Turn any path into an absolute one
realpath resolves ., .. and ~ so you know exactly where a path points before you act on it.
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 /.
Map the inventory
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.
Read the records with relative paths
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
| Command | What it does |
|---|---|
pwd | Where am I |
cd /srv/inventory | Go somewhere by absolute path |
cd servers | Go somewhere relative to here |
cd .. | Up one level |
cd | Back home |
cd - | Back to the previous directory |
What a defender takes away
- 1Absolute paths start with / and work from anywhere.
- 2Relative paths start from where you stand.
- 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.