The terminal and the shell
The terminal is the window (or app) where you type text commands. The shell is the program inside the terminal that reads what you type, runs commands, and prints results. On many Linux systems the default shell is bash, but the skills in this chapter apply to most shells.
A command line is usually made of three parts: the command name, options (also called flags), and arguments.
- Command: what to run (example:
ls). - Options: change behavior (example:
-lfor a long listing, or--allfor long-form options). - Arguments: what the command acts on (example: a file or directory name).
ls -l /etcIn that example, ls is the command, -l is an option, and /etc is an argument.
Understanding the shell prompt
The prompt is the text the shell shows to tell you it is ready for input. Prompts vary, but a common one looks like this:
alex@laptop:~/Documents$Typical parts you may see:
Continue in our app.
You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.
Or continue reading below...Download the app
- Username (
alex): who you are logged in as. - Hostname (
laptop): the machine name. - Current directory (
~/Documents): where you are in the filesystem. The~symbol means your home directory. - Prompt symbol (
$or#):$usually means a regular user;#often indicates an administrative/root shell.
When you copy commands from examples, do not type the prompt itself (do not type $ or the alex@laptop:... part). Only type the command that follows it.
Running commands and reading output
Basic workflow
Most of the time you will:
- Type a command.
- Press
Enterto run it. - Read the output.
- Return to a prompt when it finishes.
dateThis prints the current date and time, then returns you to the prompt.
Standard output vs. error output
Commands can print normal results (standard output) and also error messages (standard error). In the terminal they may look similar, but conceptually they are different streams.
Example of a successful command:
ls /etcExample that triggers an error (the directory likely does not exist):
ls /does-not-existYou should expect an error message such as “No such file or directory.” This is normal: errors are part of learning the command line. Read them carefully; they often tell you exactly what went wrong (typo, missing file, permission issue).
Exit status (success/failure)
Behind the scenes, commands return an exit status: 0 usually means success; non-zero means some kind of failure. You can view the exit status of the last command with:
echo $?Try running a successful command, then an unsuccessful one, and check $? after each to see the difference.
Speeding up typing: Tab completion
Tab completion lets the shell complete command names and paths for you. This reduces typing and prevents mistakes.
Complete a command name
Type the first few letters of a command, then press Tab:
dat<Tab>If there is only one match, it completes to date. If there are multiple matches, pressing Tab twice often shows the possibilities.
Complete a path
Tab completion is especially useful for directories and filenames:
ls /et<Tab>This should complete to /etc on most systems. You can also use it with relative paths:
ls Do<Tab>If you have a Documents directory in your current location, it may complete to Documents/.
Reusing commands: history and editing
The shell keeps a history of commands you ran. This helps you repeat or slightly modify previous commands.
Navigate history with arrow keys
- Press
Upto cycle backward through previous commands. - Press
Downto move forward again.
Once a previous command is on the line, you can edit it (use left/right arrows, backspace) and press Enter to run the modified version.
Search history interactively
In many shells, you can search your history with reverse search:
Ctrl+RStart typing part of a command you remember (for example, ls or date). Press Ctrl+R again to cycle through older matches. Press Enter to run the found command, or use arrow keys to edit it first.
List history
You can print recent commands with:
historyThis shows numbered entries. You can rerun a specific entry by recalling it (for example, by searching) and editing as needed.
Getting help: man, --help, and apropos
Linux systems include built-in documentation. Learning to access it quickly is one of the most valuable command-line skills.
man pages (manual pages)
Many commands have a manual page. Open it with:
man lsInside man:
- Use
Spaceto scroll down,bto go back. - Use
/to search within the page (type a word, pressEnter). - Press
qto quit.
Man pages often follow a pattern: NAME, SYNOPSIS (how to write the command), DESCRIPTION, and OPTIONS.
Quick help with --help
Many commands support a quick summary of usage and options:
ls --helpThis is useful when you want a fast reminder without opening man. Not every program uses the exact same format, but --help is very common.
Finding commands by keyword with apropos
If you do not know the command name, search the manual page database with apropos:
apropos copyThis returns a list of relevant manual entries containing the keyword. You can then open a promising one with man.
If apropos returns nothing, the manual database might not be updated on that system. On many distributions you can update it with an administrative command, but if you do not have permissions, you can still use --help and online documentation when needed.
Mini-lab: prompt awareness and finding help
Task 1: Identify the current user
Step-by-step:
- Run:
whoami- Compare the output to the username shown in your prompt (if your prompt includes it).
Task 2: Identify the current directory
Step-by-step:
- Run:
pwd- Confirm that the printed path matches the directory portion of your prompt (for example,
~corresponds to your home directory).
Task 3: Locate help pages for three common commands
Use three everyday commands and practice all three help methods.
Step-by-step:
- Open the man page for each command:
man lsman cdman mkdir- For each command, also try the quick help (note: some shell built-ins may behave differently):
ls --helpmkdir --help- Use
aproposto discover related entries and confirm you can find the same commands by keyword:
apropos listapropos directoryapropos make directoryAs you read help output, focus on identifying: the command’s purpose, the basic syntax, and one or two useful options you recognize.