🧀 Learn Linux

Command Reference Manual

View 237 orders by topic.

Get to know the workspace

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Go into the report directory, show the full path, and find hidden files.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
mkdir -p report
touch report/.settings report/readme.txt

examine

The path ends with /report; .settings can be found in the directory.

The path to the real terminal belongs to your computer; Tab completion, hidden files, and cd rules are directly verifiable.

Reference operation
cd report
pwd
ls -la

Organize files

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Back up note.txt to backup.txt, and then rename the original file to meeting.txt.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
printf 'meeting notes\n' > note.txt

examine

meeting.txt has the same content as backup.txt, note.txt no longer exists.

Real files may encounter permission or overwrite prompts. Only operate in this temporary directory.

Reference operation
cp note.txt backup.txt
mv note.txt meeting.txt
ls
cmp meeting.txt backup.txt

Let commands collaborate

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Write the error line to errors.txt and display it in the terminal, then check the exit code.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
printf 'INFO ready\nERROR timeout\n' > app.log

examine

Both screen and errors.txt have ERROR timeout; the exit code for the immediate pipe check is 0.

Real Shell has multiple processes and their own exit codes; the default pipe exit code is the last one.

Reference operation
grep ERROR app.log | tee errors.txt
echo $?
cat errors.txt

Read and process text

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Find the ERROR line, display the line number, and count the number of errors.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
printf 'INFO ready\nERROR timeout\nINFO done\nERROR disk\n' > app.log

examine

The error is located on lines 2 and 4 of 2. Then use less app.log to read, and press q to exit.

less will enter the paging interface; q will exit, / search. The sandbox only outputs snapshots.

Reference operation
grep -n ERROR app.log
grep -c ERROR app.log
less app.log

Permissions and links

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Make run.sh readable, writable, and executable by only you, and then actually run it.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
printf '#!/bin/sh\nprintf "ready\\n"\n' > run.sh

examine

ls -l displays -rwx------; executes the script and outputs ready.

The real system execution bit restricts script startup; the sandbox does not run arbitrary scripts, nor does it simulate full access control.

Reference operation
chmod 700 run.sh
ls -l run.sh
./run.sh

Packaging and compression

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Archive the source directory, list the contents, restore to restored, and compare the original and copy.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
mkdir source restored
printf 'hello\n' > source/note.txt

examine

The archive contains source/note.txt; the recovered text is identical to the original.

The real tar/gzip file is generated here; the sandbox only saves the teaching snapshot.

Reference operation
tar -czf source.tar.gz source
tar -tf source.tar.gz
tar -xf source.tar.gz -C restored
cmp source/note.txt restored/source/note.txt

observation system

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Check the space of the file system where the current directory is located and the occupation of this temporary directory, and then check the memory.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
printf 'sample\n' > sample.txt

examine

Can point out the Available of df and the available fields of free, and explain why the du and file byte counts may be different.

Actual results will vary from machine to machine; du counts allocated blocks, free and available are estimates of available memory.

Reference operation
df -h .
du -sh .
free -h

Troubleshoot the network

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

View the local machine address, default route and listening port, and observe the HTTPS response header.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
# 此题只读取网络状态,不修改配置。

examine

Can find the network interface, default route (if any), and HTTPS response status.

Real network requests may timeout; proxies, DNS, and offline status all affect the results. ip, ss may need to be installed first.

Reference operation
ip addr
ip route
ss -tuln
curl -I --max-time 10 https://example.com

Management services

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Read the user service list and recent user logs without changing the service status.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
# 需要使用 systemd 的 Linux;WSL 或容器可能没有服务管理器。

examine

Can distinguish active and enabled and find a log; if the environment does not support systemd, keep this question first.

Real services rely on permissions and service managers. active represents the current running, enabled represents the startup strategy.

Reference operation
systemctl --user list-units --type=service
systemctl --user list-unit-files --type=service
journalctl --user -n 5 --no-pager

mission challenge

Real terminal exercises

Operate from Linux or WSL terminal. Create a temporary exercise directory first; some parameters of macOS are different.

Task

Filter developer from the list, extract the names, sort them and remove duplicates, and save them as developers.txt.

Prepare

LAB_DIR=$(mktemp -d)
cd "$LAB_DIR"
printf 'bob,developer\nalice,designer\ncarol,developer\nbob,developer\n' > users.csv

examine

developers.txt only has bob and carol, two rows in alphabetical order.

This question combines multiple tools in a real Shell to check whether you can transfer single command knowledge to a complete process.

Reference operation
grep ',developer$' users.csv | cut -d , -f 1 | sort | uniq > developers.txt
cat developers.txt