CertNote/ Commute Study Notes
Roadmap
KOEN
CLF-C02 · FoundationalCloud Practitioner - Foundational
DVA-C02 · AssociateDeveloper - Associate
SAA-C03 · AssociateSolutions Architect - Associate
SOA-C02 · AssociateCloudOps Engineer - Associate
SAP-C02 · ProfessionalSolutions Architect - Professional
DOP-C02 · ProfessionalDevOps Engineer - Professional
Linux Master 2 · 2급KAIT Linux Master - Level 2
  • Week 1
    • 1.Operating Systems and the Kernel: What Linux Does
    • 2.The Birth of Linux: From Unix to Linus
    • 3.Free Software and Open Source: What a License Decides
    • 4.Distributions: The Unit That Bundles the Kernel and Tools for Sale
    • 5.Week 1 Review: The Identity Behind the Name Linux
  • Week 2
  • Week 3
    • 1.First Steps in the Shell: How to Read a Single Command Line
    • 2.Working with Directories and Files
    • 3.Viewing and Finding Contents
    • 4.User and Account Management
    • 5.Week 3 Review: The Commands on One Page
  • Week 4
  • Week 5
  • Week 6
  • Week 7
  • Week 8
  • Week 9
  • Week 10
  • Week 11
SCS-C03 · SpecialtySecurity - Specialty
Linux Master 1 · 1급KAIT Linux Master - Level 1
MLA-C01 · AssociateMachine Learning Engineer - Associate
AIF-C01 · FoundationalAI Practitioner - Foundational
DEA-C01 · AssociateData Engineer - Associate
MLS-C01 · SpecialtyMachine Learning - Specialty
SQLD · 개발자SQL Developer (SQLD)

© CertNote · 주간랩스

  • About
  • Changelog
  • Contact
  • Terms
  • Privacy
← Linux Master 2/Week 3/Day 1

Based on the Linux Master 2 exam syllabus·Report an error

Linux Master 2· AssociateWeek 3 · Day 1~21 min read

Day 1 - First Steps in the Shell: How to Read a Single Command Line

📌 Key Takeaways

  • The $ at the end of the prompt means a regular user, and # means root. That single character tells you your privilege level.
  • Read a command in three chunks: command [options] [arguments].
  • Options come in a short form (-a) and a long form (--all), and short forms can be combined, like -la.
  • A path starting with / is absolute; otherwise it is relative to your current location. . = current, .. = parent, ~ = home.
  • Look up unfamiliar commands with man command. Tab completion and the ↑ history cut down on typos.

Reading the Prompt

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
  • Telling $ and # apart is the most important thing. In textbooks and docs, a command that starts with # means "run this with administrator privileges."
  • The rule is not to stay logged in as root. Raise your privileges briefly with sudo only when you need to.

The Prompt Looks Different on Each Distribution

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.

FamilyWhat it looks likeCharacteristics
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 ~]#
  • Exam passages use the RedHat-family style, such as [root@www ~]#. Even if the look differs, the way you read it is the same — user, host, location, and the final $ / #.
  • In the example above, once we moved to /usr/share/doc the location slot changed to doc, and once we became root with su - the final character changed to #.
  • You can also check each piece of the prompt with a command.
whoami       # user         ← name of the logged-in user
hostname     # localhost    ← hostname
pwd          # /home/user   ← full path of the current directory

Structure of a Command

   $ ls -l /home
     │   │    │
     │   │    └── argument — on what
     │   └─────── option   — how
     └─────────── command  — what to do
ChunkDescriptionExample
CommandName of the program to runls, cp, mkdir
OptionChanges how it behaves. Usually starts with --l, -a, --help
ArgumentThe target. A file name, directory, or string/home, a.txt
  • The shell splits chunks at spaces. So if a file name contains a space, you have to wrap it in quotes or escape it with \ .
  • Commands are case-sensitive. LS is not ls.
  • Options and arguments can both be omitted. Typing just ls works, and so does giving only an argument with no option, like ls /home. The square brackets [ ] mean "optional."

Spaces Split Chunks — When You Need Quotes

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)
NotationWhat the shell does
"..." double quotesProtect spaces but substitute $variable with its value
'...' single quotesKeep every character inside exactly as written
\ backslashProtects only the one character right after it
echo "$HOME"     # /home/user   ← the variable's value is printed
echo '$HOME'     # $HOME        ← printed literally

Multiple Commands on One Line

SymbolMeaningExample
;Run in order regardless of whether the previous command succeededcd /tmp; ls
&&Run the next command only if the previous one succeededmkdir work && cd work
||Run the next command only if the previous one failedcd work || echo "not found"

Two Forms of Options

FormLookCharacteristics
Short form-aOne letter. Several can be combined → -l -a = -la
Long form--allThe meaning is clear. Cannot be combined
ls -l -a /home     # written separately
ls -la /home       # combined — same meaning
ls --all /home     # long form

Pitfall: a long form starts with -- (two hyphens). If you write it with one hyphen like -all, it is interpreted as -a -l -l.

Options That Take a Value

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 meaning
  • Here 5 is not an argument but the value of the -n option. The target the command processes (the argument) is just a.txt.
  • Most GNU commands accept --help (usage) and --version (version) in common. If you can't remember an option, start by typing command --help.

Where the Shell Looks for Commands

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/cp

What we type as a "command" is really one of three kinds.

KindDescriptionExample
Builtin commandA command that lives inside the shell program. No separate executable file is neededcd, echo, history, exit
External commandA command that exists as an executable file on disk. Found via PATHls, cp, man
AliasA short name attached to a longer commandll → ls -l
type cd      # cd is a shell builtin
type ls      # ls is aliased to `ls --color=auto'
type cp      # cp is /usr/bin/cp
  • If you get command not found, it is one of three things — a typo, the program is not installed, or the executable is outside PATH.
  • The current directory is not in 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.

Reading Paths

NotationMeaning
/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
  • Whether a path is absolute or relative depends only on whether it starts with /. This one line is an exam point.

How to Look Things Up When You Don't Know

CommandWhat it does
man commandManual page. The most standard help
command --helpA brief usage summary
info commandGNU's detailed documentation
whatis commandA one-line description
apropos keywordSearch for commands by keyword
which commandThe path of the file that gets executed
type commandWhether it is a command, an alias, or a builtin

Section Numbers of man Pages

When the same name is both a command and a configuration file, sections tell them apart.

SectionContents
1General user commands
5Configuration file formats
8System administration commands
man 1 passwd      # the passwd command
man 5 passwd      # the format of the /etc/passwd file
  • Inside man, press q to quit, page with the arrow keys or Space, and search with /word.
  • If you don't specify a section, you get only the first one found in a fixed search order. That is why 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.

SectionContentsSectionContents
1General user commands6Games
2System calls7Miscellaneous (conventions, standards, etc.)
3Library functions8System administration commands
4Special files (devices)9Kernel routines
5Configuration file formats

What Makes Up One man Page

ItemWhat it contains
NAMEThe command name and a one-line description
SYNOPSISUsage format — in what order to write options and arguments
DESCRIPTIONDetailed explanation
OPTIONSExplanation of each option
FILESRelated configuration files
SEE ALSOOther 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."
  • The number in parentheses in SEE ALSO, like passwd(5), is exactly the section number.

How the Help Commands Relate

CommandThe man option that does the sameHow it searches
whatis nameman -f nameThe one-line description of manuals whose name matches exactly
apropos keywordman -k keywordEvery 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 directories
  • If you know the command name, use whatis; if you only know what you want to do, use apropos.
  • For builtin commands, it is faster to use the shell's help, like help cd, than man.

Habits That Save Your Fingers

KeyWhat it does
TabAuto-completes commands and file names. Press twice for a list of candidates
↑ / ↓Recall previously typed commands
historyView the command history
Ctrl + CInterrupt the running command
Ctrl + DEnd input / log out
Ctrl + LClear 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.

Ctrl + C · Z · D Each Do a Different Thing

All three look like they "stop" something, but the results differ.

KeyWhat actually happensAfterward
Ctrl + CSends an interrupt signal (SIGINT) to the running commandThe command ends
Ctrl + ZSends a suspend signalThe command stays, stopped. Resume it with fg
Ctrl + DNot 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
$
  • A command stopped with Ctrl + Z has not disappeared. If you meant to terminate it, you should have used Ctrl + C.
  • When editing a line, Ctrl + A (to the start of the line) · Ctrl + E (to the end of the line) · Ctrl + U (erase before the cursor) are handy.

Tomorrow we will learn the commands that handle real files and directories using this syntax.

📖 Glossary

  • Prompt : The sign that the shell is waiting for a command. It shows the user, host, current location, and privilege.
  • Option : A marker that changes how a command behaves. There are short forms like -a and long forms like --all.
  • Argument : The target a command processes. A file name or directory name goes here.
  • Absolute path : A full path starting from /. It points to the same place regardless of the current location.
  • Relative path : A path based on the current directory.
  • Home directory : A personal directory assigned to a user. Abbreviated as ~.
  • man page : A command's official manual. Section numbers distinguish identical names.
  • Auto-completion : A feature that fills in the rest of a command or path with the Tab key.
  • Builtin command : A command that lives inside the shell, like cd. Check it with type and see its help with help.
  • PATH : The list of directories the shell searches for a command's executable. The current directory is not in it.

📝 Practice Questions

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?

PreviousWeek 2 Review: From Installation to Boot in One LineWeek 2 · Day 5Next Working with Directories and FilesWeek 3 · Day 2

Official references

  • Linux Master 2 official exam syllabus(opens in a new tab)

On this page

  • Key Takeaways
  • Reading the Prompt
  • The Prompt Looks Different on Each Distribution
  • Structure of a Command
  • Spaces Split Chunks — When You Need Quotes
  • Multiple Commands on One Line
  • Two Forms of Options
  • Options That Take a Value
  • Where the Shell Looks for Commands
  • Reading Paths
  • How to Look Things Up When You Don't Know
  • Section Numbers of man Pages
  • What Makes Up One man Page
  • How the Help Commands Relate
  • Habits That Save Your Fingers
  • Ctrl + C · Z · D Each Do a Different Thing
  • Glossary
  • Practice Questions