Skip to content
Linux Administration
Lab 1 of 27·15mBeginner

Find your way around a machine you have never seen

Answer the four questions you always ask on a new box — where am I, what is here, what is this thing, and how big is it.

You need

  • A Linux system with a shell

You will do this on every machine you ever log into. The goal is to stop guessing and start asking.

1. Where am I, and what is here

pwd
ls
ls -la

ls alone hides two things that matter: entries beginning with a dot, and everything about them. -l gives one per line with permissions, owner, size and modification time; -a includes the dotfiles. You will type ls -la for the rest of your life.

Verify

ls -la ~ # a table, one row per entry, including .bashrc or .profile

2. Move without typing full paths

cd /var/log
pwd
cd -
pwd

cd - returns to the previous directory, which is far more useful than it sounds when you are bouncing between a config directory and a log directory.

Verify

cd /etc && cd /var/log && cd - && pwd # /etc

3. Ask what a thing actually is

file /etc/hostname
file /bin/ls
file /var/log

Three different answers: text, an executable, a directory. On a strange machine, file saves you from cat-ing a binary and filling your terminal with noise.

Verify

file /bin/ls # ELF 64-bit LSB pie executable (or a symbolic link to one)

4. Find out where a command lives

which ls
command -v systemctl
type cd

type is the one that tells the truth: it distinguishes a binary from a shell builtin from an alias. cd is a builtin, which is why which cd often finds nothing.

Verify

type cd # cd is a shell builtin

5. See how much room you have

df -h
du -sh /var/log

df reports per-filesystem, du measures a directory tree. The two disagreeing is a normal state of affairs and the subject of a later lab.

Verify

df -h / # one row, with a Use% column

Where this goes next

You can orient yourself. Next: reading files without opening an editor, which is most of what you do on a server.