online posts 16
linux and the command line 101

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.

you edit, in the labanswers/1.1.yml

open a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter

given
LessonThe shell and the filesystem
Whereyour codespace’s own terminal (Ctrl+`)
Your answersanswers/1.1.yml
new to this? step by stepbeginner
  1. Open a terminal: Ctrl+`. It starts in the lab’s folder.
  2. pwd, then cd ~ and pwd again: the lab’s folder and your home folder. cd - goes back.
  3. cat /etc/os-release: the PRETTY_NAME line is the operating system.
  4. ls files, then ls -a files: the name that only appears with -a is the hidden file.
  5. Challenge: ls --help, and ls /.
  6. Fill in answers/1.1.yml, then make check T=1.1.

more in meet the lab

1 explain

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:

PathWhat it is
/the top of the tree
/etcsystem settings, as text files
/var/logthe logs
/home/vscodeyour home folder: yours to fill. ~ is short for it
/workspaces/linux-cli-101the 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.

2 show

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.

3 follow along

Find your bearings

  1. Open a terminal of your own: Ctrl+`, or Terminal → New Terminal. Where does it start?

    run in the terminal
    pwd
    
  2. Go home, ask again, then come back. cd with ~ (or with nothing at all) goes home; cd - goes back to wherever you were before:

    run in the terminal
    cd ~
    pwd
    cd -
    
  3. Which Linux is this? Most distributions describe themselves in one small text file:

    run in the terminal
    cat /etc/os-release
    

    Read the PRETTY_NAME= line.

  4. Look in files/, first the normal way, then with the hidden files:

    run in the terminal
    ls files
    ls -a files
    cat files/.lab-notes
    
  5. Open 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.yml
    home: /home/vscode
    repo: /workspaces/linux-cli-101
    os: Debian GNU/Linux 12 (bookworm)
    hidden_file: .lab-notes
    

    On a laptop, repo is wherever you cloned the lab: write what pwd printed. 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.

4 challenge

Ask the command

You don’t have to remember every option. Almost every command explains itself.

  1. ls -l prints sizes in bytes. Which option makes it print them as 4.0K and 1.2M instead? Find it in ls --help. It’s a long list: ls --help | less lets you scroll it with the arrow keys, and q quits. Put the option in ls_sizes_option.
  2. ls / lists the top of the tree. Which of those folders holds the system’s logs? Write its absolute path in logs_folder, then try ls on 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.1

when 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