task 1.1 · chapter 1 of 8: the shell and the filesystem · 20 min
Where am I?
objective
Find out where a new terminal puts you, where your home folder is, which Linux you’re on, and what’s in the lab’s files/ folder, hidden files included. Then use a command’s own help to find an option.
answers/1.1.ymlopen a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter
| Lesson | The shell and the filesystem |
|---|---|
| Where | your codespace’s own terminal (Ctrl+`) |
| Your answers | answers/1.1.yml |
new to this? step by stepbeginner
- Open a terminal: Ctrl+`. It starts in the lab’s folder.
pwd, thencd ~andpwdagain: the lab’s folder and your home folder.cd -goes back.cat /etc/os-release: the PRETTY_NAME line is the operating system.ls files, thenls -a files: the name that only appears with-ais the hidden file.- Challenge:
ls --help, andls /. - Fill in answers/1.1.yml, then
make check T=1.1.
more in meet the lab
The shell, and one tree of files
What you’re typing into
The window at the bottom of VS Code is a terminal. Inside it runs a shell: the program that reads what
you type, runs it, and shows you what it printed. This lab’s shell is bash, the one on almost every Linux
server. Meet the lab showed you pwd, ls, cd and cat; this chapter is about
what they tell you.
A command line has three kinds of words:
ls -la files
│ │ └── an argument: what to work on
│ └─────── options: how to do it (-l long listing, -a all files)
└─────────── the command
in one sentence A command, then options that change how it works, then arguments that say what it works on.
One tree, starting at /
Linux has no C: or D: drive. Every file on the computer hangs from one tree, and the top of it is called
/ (the root). A path says how to walk the tree to a file, folder by folder, with a / between each:
| Path | What it is |
|---|---|
/ | the top of the tree |
/etc | system settings, as text files |
/var/log | the logs |
/home/vscode | your home folder: yours to fill. ~ is short for it |
/workspaces/linux-cli-101 | the lab’s folder, where Codespaces put the repository |
A path that starts with / is absolute: it works from anywhere. One that doesn’t is relative: it starts
from the folder you’re in now, your working directory, which pwd (print working directory) prints.
in one sentence An absolute path starts at /; a relative one starts wherever you are now.
Hidden files
A file whose name starts with a dot, like .bashrc, is hidden: ls leaves it out unless you ask for
all with -a. Nothing about the file is secret. It’s a convention to keep settings files out of the way.
What the codespace says
A new terminal, in the lab:
vscode ➜ /workspaces/linux-cli-101 (main) $ pwd
/workspaces/linux-cli-101
vscode ➜ /workspaces/linux-cli-101 (main) $ ls
Makefile README.md answers captures checks files hosts.txt lab reports requirements.txt scripts
The prompt itself already says who you are (vscode, the lab’s user), where you
are, and which Git branch the folder is on. The bit you type starts after the $.
ls -la files, the long listing of all files:
total 36
drwxr-xr-x 7 vscode vscode 4096 Nov 11 05:51 .
drwxr-xr-x 14 vscode vscode 4096 Nov 11 05:52 ..
-rw-r--r-- 1 vscode vscode 77 Nov 11 05:51 .lab-notes
drwxr-xr-x 4 vscode vscode 4096 Nov 11 05:52 backups
drwxr-xr-x 2 vscode vscode 4096 Nov 11 05:51 configs
-rw-r--r-- 1 vscode vscode 191 Nov 11 05:51 labinfo
drwxr-xr-x 2 vscode vscode 4096 Nov 11 05:51 logs
...
A d at the start of a line is a folder (a directory); a - is a file. . is the folder itself and .. is
the one above it; every folder has both. Chapter 4 reads the rest of each line.
Find your bearings
Open a terminal of your own: Ctrl+`, or Terminal → New Terminal. Where does it start?
run in the terminalpwdGo home, ask again, then come back.
cdwith~(or with nothing at all) goes home;cd -goes back to wherever you were before:run in the terminalcd ~ pwd cd -Which Linux is this? Most distributions describe themselves in one small text file:
run in the terminalcat /etc/os-releaseRead the
PRETTY_NAME=line.Look in
files/, first the normal way, then with the hidden files:run in the terminalls files ls -a files cat files/.lab-notesOpen answers/1.1.yml (Ctrl+P, type
1.1.yml) and fill in the follow-along lines. Paths are absolute; the operating system goes in without its quotes:editanswers/1.1.ymlCtrl+P → 1.1.ymlhome: /home/vscode repo: /workspaces/linux-cli-101 os: Debian GNU/Linux 12 (bookworm) hidden_file: .lab-notesOn a laptop,
repois wherever you cloned the lab: write whatpwdprinted. Save with Ctrl+S.
in one sentence pwd says where you are, cd ~ takes you home, ls -a shows the files whose names start with a dot.
Ask the command
You don’t have to remember every option. Almost every command explains itself.
ls -lprints sizes in bytes. Which option makes it print them as4.0Kand1.2Minstead? Find it inls --help. It’s a long list:ls --help | lesslets you scroll it with the arrow keys, and q quits. Put the option inls_sizes_option.ls /lists the top of the tree. Which of those folders holds the system’s logs? Write its absolute path inlogs_folder, then trylson it.
Then run make check T=1.1.
hint
In ls --help, look for the word human. man ls is the longer manual page for the same thing.
hint
The logs folder is two levels down: a short folder name, then log.
show the solution
ls_sizes_option: -h
logs_folder: /var/log
-h, --human-readable with -l and -s, print sizes like 1K 234M 2G etc.
ls -lh is the combination you’ll type most. --help is the short version that almost every command has;
man ls is the manual, with every option explained (q quits it too).
5 check: run it, then prove it
$ make check T=1.1when it's right, you'll see
╭─ task 1.1 · where am I?
│ ✓ your home folder (follow along): /home/vscode
│ ✓ the lab's folder (follow along): /workspaces/linux-cli-101
│ ✓ the operating system (follow along): Debian GNU/Linux 12 (bookworm)
│ ✓ the hidden file in files/ (follow along): .lab-notes
│ ✓ the ls option for sizes in K and M (challenge): ...
│ ✓ where Linux keeps its logs (challenge): ...
╰─ 6/6 checks passed verified