2.1 Command Line Basics (Weight: 3)
📘Linux Essentials (LPI 010-160)
This topic is very important for the Linux Essentials exam. You must clearly understand what a shell is, how commands are written, and how the command line works.
This section explains everything in simple English so that both IT and non-IT learners can understand easily.
1. What is the Shell?
The shell is a program that allows users to interact with the Linux system by typing commands.
It works as a bridge between:
- The user
- The Linux kernel
The shell:
- Reads your command
- Understands it
- Tells the system what to do
- Shows the output
Without the shell, you cannot use the command line.
2. What is a Terminal?
A terminal is a program that gives you access to the shell.
In a graphical desktop environment, you open a terminal application to:
- Type commands
- Manage files
- Install software
- Configure services
- Check system status
The terminal shows a prompt like this:
user@hostname:~$
This is called the shell prompt.
3. Popular Linux Shells
There are different shell programs in Linux.
The most common shell is:
- Bash
Bash stands for:
Bourne Again Shell
Other shells exist, but for the exam, you mainly focus on Bash.
You can check your current shell with:
echo $SHELL
4. Basic Structure of a Command
Every Linux command follows a simple structure:
command [options] [arguments]
Let’s understand each part clearly.
4.1 Command
The command is the program you want to run.
Examples:
ls
pwd
mkdir
cp
Each command performs a specific task.
4.2 Options (Flags or Switches)
Options modify how a command works.
They usually start with:
- A single dash:
- - Or double dash:
--
Examples:
ls -l
ls -a
ls -la
-l→ long listing format-a→ show hidden files
Options can be combined:
ls -la
This means:
-l- and
-a
Some commands use long options:
ls --all
4.3 Arguments
Arguments tell the command what to work on.
Example:
ls /home
ls→ command/home→ argument (directory)
Another example:
mkdir project
mkdir→ commandproject→ argument (new directory name)
5. Case Sensitivity in Linux
Linux is case-sensitive.
This means:
file.txt
File.txt
FILE.txt
All three are different.
Commands are also case-sensitive:
ls ✓ correct
LS ✗ wrong
For the exam, always remember:
Linux treats uppercase and lowercase differently.
6. Types of Commands
There are three main types of commands:
6.1 Internal Commands
These are built into the shell.
Examples:
cd
echo
pwd
They run directly inside Bash.
6.2 External Commands
These are separate programs stored in system directories.
Examples:
ls
cp
mv
They are stored in directories like:
/bin
/usr/bin
You can check where a command is located:
which ls
6.3 Aliases
Aliases are shortcuts for commands.
Example:
alias ll='ls -l'
Now typing:
ll
Runs:
ls -l
To see all aliases:
alias
7. Getting Help in the Shell
Very important for the exam.
Linux provides built-in help systems.
7.1 –help Option
Most commands support:
command --help
Example:
ls --help
7.2 Man Pages
Manual pages show detailed documentation.
man ls
To search inside man:
- Press
/ - Type word
- Press Enter
To exit:
q
7.3 Info Pages
Some programs use:
info command
Example:
info ls
8. Running Multiple Commands
You can combine commands in different ways.
8.1 Run One After Another (Always)
command1 ; command2
Example:
mkdir test ; cd test
Both commands run, even if the first fails.
8.2 Run Only if First Succeeds
command1 && command2
Second runs only if first is successful.
Used often in:
- Software installation
- Service configuration
8.3 Run if First Fails
command1 || command2
Second runs only if first fails.
9. Command History
The shell stores previous commands.
Use:
history
To run a previous command:
!number
Example:
!45
Runs command number 45.
Use arrow keys:
- Up arrow → previous command
- Down arrow → next command
10. Wildcards (Globbing)
Wildcards help match multiple files.
10.1 Asterisk (*)
Matches multiple characters.
ls *.txt
Shows all files ending with .txt.
10.2 Question Mark (?)
Matches exactly one character.
ls file?.txt
Matches:
file1.txt
fileA.txt
10.3 Square Brackets []
Matches specific characters.
ls file[123].txt
Matches:
file1.txt
file2.txt
file3.txt
11. Quotes in Linux
Quotes are very important in command syntax.
11.1 Double Quotes (” “)
Allow variable expansion.
Example:
echo "My home is $HOME"
11.2 Single Quotes (‘ ‘)
Prevent variable expansion.
echo 'My home is $HOME'
Prints exactly:
My home is $HOME
12. Variables in the Shell
A variable stores a value.
Example:
name=admin
To use it:
echo $name
Environment variables:
echo $HOME
echo $PATH
13. Special Characters
Some characters have special meaning:
> redirect output
< redirect input
| pipe output
& run in background
Example:
ls > files.txt
This saves output into a file.
14. Exit Status (Very Important for Exam)
Every command returns an exit status.
0→ success- Non-zero → error
Check exit status:
echo $?
This is very important in scripting and automation.
15. Root User and Permissions
Some commands require administrator privileges.
To run as root:
sudo command
In IT environments:
- Used to install software
- Modify system configuration
- Restart services
16. Tab Completion
Press:
Tab
It:
- Auto-completes commands
- Auto-completes file names
- Reduces typing errors
Very useful in real IT work environments.
17. Clearing the Screen
clear
Or:
Ctrl + L
18. Important Exam Points Summary
For the LPI 010-160 exam, you must know:
✔ What a shell is
✔ What Bash is
✔ Command structure (command + options + arguments)
✔ Difference between internal and external commands
✔ How to get help (man, –help)
✔ Wildcards (*, ?, [])
✔ Command history
✔ Exit status ($?)
✔ Variables and quoting
✔ Command chaining (;, &&, ||)
✔ Case sensitivity
✔ Tab completion
Final Notes for Students
Understanding the command line is the foundation of Linux administration.
In IT environments, system administrators use the shell to:
- Manage servers
- Configure services
- Automate tasks
- Monitor system performance
- Install and manage software
- Troubleshoot issues
The shell is powerful, fast, and efficient.
For the exam, focus on:
- Syntax
- Structure
- Behavior of commands
- Understanding output
If you master this topic, you build a strong base for the rest of Linux Essentials.
