Linux / Basic: command-line foundations / Lesson 1
Understand the shell and find reliable help
Learn how a terminal, a shell, and Linux programs cooperate, then use local documentation to investigate commands before running them.
On this page
Lesson goals
- Distinguish terminal, shell, kernel, and distribution.
- Read command syntax and identify builtins and external programs.
- Use help and exit status as evidence.
The layers behind a prompt
Linux is the kernel: it manages processes, memory, devices, and access to system resources. A distribution combines that kernel with libraries, utilities, a package manager, and installation choices. The terminal is an input and display program. A shell, such as Bash, reads commands from that terminal or from a script. These boundaries explain why changing the terminal appearance does not change command syntax, and why a command available on one distribution may be absent on another.
Commands are structured arguments
A simple command normally starts with a command name followed by arguments. Options change behavior; operands identify the objects to process. Spaces separate words unless quoting groups them. The prompt itself is decoration and must not be copied as part of a command. A name can resolve to a shell builtin, function, alias, or executable found through PATH. Use type to inspect that resolution instead of assuming that every familiar name refers to a file in a particular directory.
type cd
printf '%s\n' 'hello lab'
Bash reports that cd is a builtin; printf then writes the quoted argument followed by a newline. The exact wording from type can vary with the shell locale.
Choose the right documentation
For Bash builtins, help cd describes the implementation already running. For installed commands, man command opens the locally installed manual when the manual package is present. Manual sections matter: section 1 covers user commands, section 5 file formats, and section 8 administration. Use man 5 passwd to study the account-file format rather than the password-changing command. Read the synopsis first, then the option details and exit-status section. Square brackets in a synopsis indicate optional material; they are usually not literal characters to type.
Observe results and exit status
Programs communicate through output and an exit status. A status of zero conventionally means success; nonzero values need interpretation using that program’s documentation. Bash exposes the most recent status as $?, but the next command replaces it. Output is not proof of success, and silence is not proof of failure. Capture status immediately when investigating an unexpected result. Standard output carries useful data, while standard error normally carries diagnostics; later lessons show how to keep these channels separate.
false
printf 'status=%s\n' "$?"
true
printf 'status=%s\n' "$?"
status=1
status=0
false and true are harmless test commands. Each printf expands $? before printf itself changes the status.
Build an investigation habit
Practice as an ordinary user in a disposable directory or virtual machine. Read examples before copying them, identify every path and option, and distinguish a displayed illustration from an instruction for your computer. Administrative commands in this course are study examples marked non-runnable. Record the distribution release and relevant tool version when comparing documentation. Upstream manuals describe current software, while your installed release may implement an older feature set. When help differs, trust the locally installed manual for the executable you will actually use.
Common errors and fixes
command not found
- Why it happens
- The name is misspelled, the package is absent, or PATH does not include its directory.
- How to fix it
- Check spelling, then inspect type and the distribution package documentation.
- Prevent it next time
- Verify command availability before adapting an example.
Copying synopsis punctuation
- Why it happens
- Optional brackets and alternatives were mistaken for literal arguments.
- How to fix it
- Read the manual conventions and choose one concrete invocation.
- Prevent it next time
- Translate each synopsis into words before typing it.
Reading a stale $?
- Why it happens
- Another command ran before the status was inspected.
- How to fix it
- Capture the status immediately in a variable.
- Prevent it next time
- Treat status as part of the same observation as output.
Check your understanding
1. Explain why help cd is more direct than searching for a cd executable.
Show worked solution
Changing directories must affect the current shell, so Bash implements cd internally. type cd reveals the resolution, and help cd describes that builtin. A child executable cannot change its parent shell’s working directory.
2. A command prints nothing and returns zero. What can you conclude, and what should you check next?
Show worked solution
The command reports success by its exit-status convention. Silence alone says nothing about the amount of work done. Read its documented behavior and inspect the intended result, such as a generated file, without assuming that visible output was required.
Key takeaways
- Identify the executing shell and command before trusting syntax.
- Use local help, explicit manual sections, and immediate status checks.