Based on the Linux Master 2 exam syllabusReport an error
$ at the end of the prompt means a regular user, and # means root. That single character tells you your privilege level.command [options] [arguments].-a) and a long form (--all), and short forms can be combined, like -la./ is absolute; otherwise it is relative to your current location. . = current, .. = parent, ~ = home.man command. Tab completion and the ↑ history cut down on typos.When you log in, a line like this appears. This is the prompt, the sign that the shell is waiting for a command.
user@localhost:~$
│ │ ││
│ │ │└── $ = regular user, # = root
│ │ └─── current directory (~ is the home directory)
│ └────────── hostname (the computer's name)
└───────────────── name of the logged-in user$ and # apart is the most important thing. In textbooks and docs, a command that starts with # means "run this with administrator privileges."sudo only when you need to.The prompt is drawn according to the format stored in a variable called PS1. The defaults differ by distribution, so the same situation looks different.
| Family | What it looks like | Characteristics |
|---|---|---|
| RedHat family (CentOS · Rocky) | [user@localhost ~]$ | Wrapped in square brackets, and shows only the last name of the current directory |
| Debian family (Ubuntu) | user@localhost:~$ | Joined with a colon, and shows the full path of the current directory |
[user@localhost ~]$ cd /usr/share/doc
[user@localhost doc]$ su -
Password:
[root@localhost ~]#[root@www ~]#. Even if the look differs, the way you read it is the same — user, host, location, and the final $ / #./usr/share/doc the location slot changed to doc, and once we became root with su - the final character changed to #.whoami # user ← name of the logged-in user
hostname # localhost ← hostname
pwd # /home/user ← full path of the current directory $ ls -l /home
│ │ │
│ │ └── argument — on what
│ └─────── option — how
└─────────── command — what to do| Chunk | Description | Example |
|---|---|---|
| Command | Name of the program to run | ls, cp, mkdir |
| Option | Changes how it behaves. Usually starts with - | -l, -a, --help |
| Argument | The target. A file name, directory, or string | /home, a.txt |
\ .LS is not ls.ls works, and so does giving only an argument with no option, like ls /home. The square brackets [ ] mean "optional."touch my file.txt # two files get created: my and file.txt
touch "my file.txt" # one file containing a space
touch my\ file.txt # same as above (\ protects the one space right after it)| Notation | What the shell does |
|---|---|
"..." double quotes | Protect spaces but substitute $variable with its value |
'...' single quotes | Keep every character inside exactly as written |
\ backslash | Protects only the one character right after it |
echo "$HOME" # /home/user ← the variable's value is printed
echo '$HOME' # $HOME ← printed literally| Symbol | Meaning | Example |
|---|---|---|
; | Run in order regardless of whether the previous command succeeded | cd /tmp; ls |
&& | Run the next command only if the previous one succeeded | mkdir work && cd work |
|| | Run the next command only if the previous one failed | cd work || echo "not found" |
| Form | Look | Characteristics |
|---|---|---|
| Short form | -a | One letter. Several can be combined → -l -a = -la |
| Long form | --all | The meaning is clear. Cannot be combined |
ls -l -a /home # written separately
ls -la /home # combined — same meaning
ls --all /home # long formPitfall: a long form starts with
--(two hyphens). If you write it with one hyphen like-all, it is interpreted as-a -l -l.
Some options are followed by a value. Short forms usually separate it with a space, and long forms usually join it with =.
head -n 5 a.txt # short form + value
head --lines=5 a.txt # long form + value — same meaning5 is not an argument but the value of the -n option. The target the command processes (the argument) is just a.txt.--help (usage) and --version (version) in common. If you can't remember an option, start by typing command --help.The reason typing just ls works is that the shell searches the directories listed in the PATH variable from the front, one by one, looking for an executable file with the same name.
echo $PATH
# /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user/bin
which cp
# /usr/bin/cpWhat we type as a "command" is really one of three kinds.
| Kind | Description | Example |
|---|---|---|
| Builtin command | A command that lives inside the shell program. No separate executable file is needed | cd, echo, history, exit |
| External command | A command that exists as an executable file on disk. Found via PATH | ls, cp, man |
| Alias | A short name attached to a longer command | ll → ls -l |
type cd # cd is a shell builtin
type ls # ls is aliased to `ls --color=auto'
type cp # cp is /usr/bin/cpcommand not found, it is one of three things — a typo, the program is not installed, or the executable is outside PATH.PATH. So to run an executable in your current location, you add a path like ./script.sh.which finds the location of an executable in PATH, while type also tells you whether the name is a builtin, an alias, or external. A builtin may have no executable file of its own, so checking with type is more accurate.| Notation | Meaning |
|---|---|
/ | The root directory. The starting point of every path |
. | The current directory |
.. | One level up (the parent directory) |
~ | The current user's home directory |
- | The directory you were in just before (cd -) |
Absolute path /home/user/docs/a.txt ← starts with /. Same place wherever you run it
Relative path docs/a.txt ← relative to the current location
../user2/b.txt ← go up one level, then down/. This one line is an exam point.| Command | What it does |
|---|---|
man command | Manual page. The most standard help |
command --help | A brief usage summary |
info command | GNU's detailed documentation |
whatis command | A one-line description |
apropos keyword | Search for commands by keyword |
which command | The path of the file that gets executed |
type command | Whether it is a command, an alias, or a builtin |
When the same name is both a command and a configuration file, sections tell them apart.
| Section | Contents |
|---|---|
| 1 | General user commands |
| 5 | Configuration file formats |
| 8 | System administration commands |
man 1 passwd # the passwd command
man 5 passwd # the format of the /etc/passwd fileman, press q to quit, page with the arrow keys or Space, and search with /word.man passwd shows the command (1), and you must specify 5 to see the file format.There are originally nine sections. The exam mostly asks about 1, 5, and 8, but knowing the whole picture keeps you from getting confused.
| Section | Contents | Section | Contents |
|---|---|---|---|
| 1 | General user commands | 6 | Games |
| 2 | System calls | 7 | Miscellaneous (conventions, standards, etc.) |
| 3 | Library functions | 8 | System administration commands |
| 4 | Special files (devices) | 9 | Kernel routines |
| 5 | Configuration file formats |
| Item | What it contains |
|---|---|
| NAME | The command name and a one-line description |
| SYNOPSIS | Usage format — in what order to write options and arguments |
| DESCRIPTION | Detailed explanation |
| OPTIONS | Explanation of each option |
| FILES | Related configuration files |
| SEE ALSO | Other manuals to look at together |
SYNOPSIS
ls [OPTION]... [FILE]...[ ] means optional, and ... means you can chain several. The line above reads as "you can give no options and no files, and you can also give several."SEE ALSO, like passwd(5), is exactly the section number.| Command | The man option that does the same | How it searches |
|---|---|---|
whatis name | man -f name | The one-line description of manuals whose name matches exactly |
apropos keyword | man -k keyword | Every manual whose name or description contains the keyword |
whatis passwd
# passwd (1) - update user's authentication tokens
# passwd (5) - password file
apropos "copy files"
# cp (1) - copy files and directorieswhatis; if you only know what you want to do, use apropos.help, like help cd, than man.| Key | What it does |
|---|---|
| Tab | Auto-completes commands and file names. Press twice for a list of candidates |
| ↑ / ↓ | Recall previously typed commands |
history | View the command history |
| Ctrl + C | Interrupt the running command |
| Ctrl + D | End input / log out |
| Ctrl + L | Clear the screen (same as clear) |
Tab completion not only cuts down typos but is also a way to check that a path is right. If it won't complete, that path doesn't exist.
All three look like they "stop" something, but the results differ.
| Key | What actually happens | Afterward |
|---|---|---|
| Ctrl + C | Sends an interrupt signal (SIGINT) to the running command | The command ends |
| Ctrl + Z | Sends a suspend signal | The command stays, stopped. Resume it with fg |
| Ctrl + D | Not a signal but a marker meaning "input has ended" (EOF) | A command waiting for input exits normally. At an empty prompt, it logs you out |
$ sleep 100
^Z
[1]+ Stopped sleep 100
$ fg
sleep 100
^C
$Ctrl + Z has not disappeared. If you meant to terminate it, you should have used Ctrl + C.Tomorrow we will learn the commands that handle real files and directories using this syntax.
-a and long forms like --all./. It points to the same place regardless of the current location.~.cd. Check it with type and see its help with help.Click a choice to reveal the answer and explanation.
Question 1
When the last character of the shell prompt is #, which of the following can you tell?
Question 2
Which of the following commands has the same meaning as ls -l -a?
Question 3
Which of the following is an absolute path?
Question 4
Which command should you use to view the manual for the **format of the /etc/passwd file**?
Question 5
Which of the following key combinations is used to forcibly interrupt a running command?