Linux Terminal Basics
Chapter Overview
In this chapter you will learn:
- What is a terminal
- What is a shell
- GUI vs CLI
- Bash shell
- Command syntax
- Arguments and flags
- Command history
- Tab completion
- Wildcards
- Pipes
- Input and output redirection
- Environment variables
- Terminal productivity tips
Introduction
One of the biggest strengths of Linux is:
The Command Line Interface (CLI)
Most Linux servers do not even have a graphical interface. Everything is managed using:
Terminal
This is why learning the terminal is extremely important.
What is a Terminal?
A terminal is a program that allows users to interact with Linux using commands. Examples:
- GNOME Terminal
- Konsole
- XTerm
- Windows Terminal
- Terminator
Visualization
User
↓
Terminal
↓
Shell
↓
Linux Kernel
↓
Hardware
Terminal vs Shell
Many beginners think they are the same. They are not.
Terminal
A program that displays text and accepts input. Examples:
GNOME Terminal
Konsole
Windows Terminal
Shell
A program that interprets commands. Examples:
Bash
ZSH
Fish
SH
Example
You type:
ls
Flow:
Terminal
↓
Shell
↓
Kernel
↓
Filesystem
What is CLI?
CLI means:
Command Line Interface
You interact using commands. Example:
mkdir Projects
GUI vs CLI
| Feature | GUI | CLI |
|---|---|---|
| Easy for Beginners | ✅ | ❌ |
| Speed | Medium | Fast |
| Automation | Limited | Excellent |
| Remote Management | Medium | Excellent |
| Server Usage | Low | Very High |
Why Professionals Prefer CLI
CLI allows: ✅ Automation ✅ Remote Administration ✅ Scripting ✅ Server Management ✅ Faster Workflows
Example
Create 1000 folders: GUI:
Almost impossible.
CLI:
mkdir folder{1..1000}
Done instantly.
Linux Shell
A shell is a command interpreter. It receives commands and executes them.
Popular Shells
Bash
Default on many Linux systems.
Bourne Again Shell
Most popular.
ZSH
Advanced shell. Popular with developers. Features:
- Better autocompletion
- Themes
- Plugins
Fish
Beginner friendly.
Check Current Shell
echo $SHELL
Example:
/bin/bash
Starting Bash
bash
Exiting Shell
exit
Command Structure
Almost every Linux command follows:
command [options] [arguments]
Example
ls -la /home
Breakdown:
ls → command
-la → options
/home → argument
Another Example
cp file.txt backup.txt
Breakdown:
cp → command
file.txt → source
backup.txt → destination
Commands
Commands are programs. Examples:
ls
cp
mv
rm
mkdir
cat
Arguments
Arguments provide data to commands. Example:
cd Documents
Argument:
Documents
Options / Flags
Flags modify command behavior. Example:
ls -l
Flag:
-l
Multiple Flags
ls -la
Equivalent to:
ls -l -a
Common Syntax
command -options arguments
Long Options
Example:
ls --all
Getting Help
One of the most important commands:
man
Example:
man ls
Manual Pages
Shows:
- Description
- Options
- Examples Exit:
q
Quick Help
ls --help
Linux Prompt
Example:
aayan@ubuntu:~$
Breakdown:
aayan → username
ubuntu → hostname
~ → current directory
$ → normal user
Root Prompt
root@ubuntu:~#
Notice:
#
means root user.
Current Directory
Display:
pwd
Example:
/home/aayan
Command History
Linux stores previously executed commands. View:
history
Example
1 ls
2 pwd
3 cd Documents
Run Previous Command
!!
Run Specific Command
!100
Runs command number 100.
Search History
Press:
CTRL + R
Type:
ssh
Linux searches previous commands. Huge productivity boost.
Tab Completion
One of Linux's best features.
Example: Type:
cd Doc
Press:
TAB
Automatically becomes:
cd Documents
Double TAB
Shows possible matches.
Command Editing Shortcuts
Move Cursor
Beginning:
CTRL + A
End:
CTRL + E
Delete
Delete word:
CTRL + W
Clear line:
CTRL + U
Clear screen:
CTRL + L
Equivalent:
clear
Wildcards
Wildcards help work with multiple files.
*
Matches everything. Example:
ls *
Delete all text files:
rm *.txt
?
Matches one character. Example:
ls file?.txt
Matches:
file1.txt
fileA.txt
[]
Character ranges. Example:
ls file[1-5].txt
Example:
ls file[a-z].txt
Brace Expansion
Very powerful. Create folders:
mkdir folder{1..10}
Creates:
folder1
folder2
folder3
Create files:
touch file{1..100}.txt
Quotes
Single Quotes
echo '$HOME'
Output:
$HOME
Double Quotes
echo "$HOME"
Output:
/home/aayan
Environment Variables
Variables used by Linux.
View all:
env
Important Variables
HOME
echo $HOME
Example:
/home/aayan
USER
echo $USER
PATH
echo $PATH
Example:
/usr/bin:/bin:/usr/local/bin
PATH Variable
Linux searches commands inside PATH. Example:
ls
Actually:
/usr/bin/ls
View Command Location
which ls
Create Variables
name="Aayan"
Use:
echo $name
Export Variables
export JAVA_HOME=/usr/lib/java
Input and Output Streams
Linux uses three standard streams.
Standard Input
stdin
0
Standard Output
stdout
1
Standard Error
stderr
2
Redirection
One of Linux's most powerful features.
Output Redirection
>
Overwrite file.
echo hello > test.txt
>>
Append.
echo world >> test.txt
Input Redirection
cat < file.txt
Error Redirection
command 2> errors.txt
Redirect Everything
command > output.txt 2>&1
Pipes
Pipes send output of one command to another. Symbol:
|
Visualization
Command1
↓
PIPE
↓
Command2
Example
ls | less
Example:
cat file.txt | grep admin
Example:
ps aux | grep apache
Why Pipes Are Powerful
You can combine commands. Example:
cat logs.txt | grep ERROR | wc -l
Meaning:
Find ERROR lines
Count them
Command Chaining
&&
Run second command if first succeeds.
mkdir test && cd test
||
Run second if first fails.
cd folder || echo Failed
;
Always run next command.
pwd ; ls
Running Background Processes
Use:
&
Example:
python app.py &
Jobs
View:
jobs
Stop Process
Press:
CTRL + C
Suspend Process
Press:
CTRL + Z
Linux Command Lifecycle
Example:
ls -la
Flow:
User
↓
Terminal
↓
Shell
↓
Kernel
↓
Filesystem
↓
Output
Real World Example
PocketMine Hosting:
cd /home/minecraft/server
php start.php
Web Hosting:
cd /var/www/html
nano index.php
System Administration:
cat /var/log/syslog | grep ssh
Productivity Tips
Use TAB
Avoid typing full names.
Use History
CTRL + R
Learn Pipes
Pipes make Linux powerful.
Read Manuals
man command
Exercises
Exercise 1
Find your current shell.
Exercise 2
Display PATH variable.
Exercise 3
Create variables.
Exercise 4
Redirect output to file.
Exercise 5
Use grep with pipes.
Exercise 6
Use history search.
Mini Project
Create files:
touch file{1..20}.txt
Use:
- wildcards
- pipes
- redirection
- history
- variables
Summary
You learned: ✅ Terminal ✅ Shell ✅ Bash ✅ Commands ✅ Flags ✅ Arguments ✅ Environment Variables ✅ Wildcards ✅ Pipes ✅ Redirection ✅ History ✅ Productivity Features This chapter forms the foundation of all Linux administration.
References
Bash Manual: https://www.gnu.org/software/bash/ Linux Documentation: https://linuxcommand.org/
Next Chapter
➡ pwd Command ➡ ls Command ➡ cd Command ➡ mkdir Command ➡ Linux Navigation Exercises