Linux Commands
Linux commands are programs or shell features used to interact with the Linux operating system through the terminal.
Basic flow:
User ↓ Terminal ↓ Shell (Bash/Zsh/etc.) ↓ Command ↓ Linux Kernel / System Resources ↓ Result
For example:
ls
asks the shell to execute the ls program, which lists directory contents.
1. Basic Command Structure
Most Linux commands follow:
command [options] [arguments]
Example:
ls -lah /home
Here:
ls → command -lah → options /home → argument
Another example:
cp file.txt backup.txt
cp → command file.txt → source backup.txt → destination
2. Getting Help
Before learning individual commands, know how to get help.
man
Displays the manual page.
man ls
Example:
man chmod
You can search within a man page using:
/search_term
Exit:
q
--help
Many commands support:
ls --help
or:
cp --help
This provides a quick usage summary.
whatis
Provides a short description.
whatis ls
Example:
ls (1) - list directory contents
apropos
Searches manual-page descriptions for a keyword.
apropos network
3. Navigation Commands
These commands are essential.
pwd
Print Working Directory
Shows your current location.
pwd
Example:
/home/uday
Meaning:
You are currently inside
/home/uday.
4. ls
Lists directory contents.
ls
Example:
Documents Downloads Music Pictures
Long format
ls -l
Example:
-rw-r--r-- file.txt drwxr-xr-x Documents
Show hidden files
ls -a
Long + hidden
ls -la
Human-readable sizes
ls -lh
Common combination:
ls -lah
5. cd
Change Directory
cd Documents
Move into Documents.
Go to parent
cd ..
Go to home directory
cd ~
or simply:
cd
Go to root
cd /
Go to previous directory
cd -
Example:
/home/uday ↓ cd Documents ↓ /home/uday/Documents
6. Special Path Symbols
. → current directory .. → parent directory ~ → current user's home directory / → filesystem root
Example:
cd ../Downloads
7. Creating Directories
mkdir
Creates a directory.
mkdir test
Multiple directories:
mkdir dir1 dir2 dir3
Create nested directories
mkdir -p project/src/python
-p creates missing parent directories.
8. Creating Files
touch
Creates an empty file if it doesn't exist, or updates timestamps if it does.
touch file.txt
Multiple files:
touch a.txt b.txt c.txt
9. Viewing File Contents
cat
Displays the contents of a file.
cat file.txt
Example:
Hello Linux This is my file.
less
Useful for large files.
less file.txt
Navigate with:
↑ ↓ Page Up Page Down
Exit:
q
more
Another pager:
more file.txt
head
Shows the beginning of a file.
head file.txt
First 10 lines by default.
head -n 20 file.txt
Shows first 20 lines.
tail
Shows the end of a file.
tail file.txt
Last 10 lines by default.
tail -n 20 file.txt
Follow a changing file
tail -f /var/log/some.log
Useful for watching logs in real time.
10. Copying Files
cp
Copies files/directories.
cp file.txt backup.txt
Copy into a directory:
cp file.txt Documents/
Copy directory recursively:
cp -r project backup/
Modern systems may also support:
cp -a project backup/
-a preserves attributes and copies recursively.
11. Moving and Renaming
mv
Move:
mv file.txt Documents/
Rename:
mv old.txt new.txt
Move and rename:
mv old.txt Documents/new.txt
12. Deleting Files
rm
Delete a file:
rm file.txt
Delete multiple:
rm a.txt b.txt
Delete directory recursively
rm -r directory
Force
rm -f file.txt
Recursive + force
rm -rf directory
⚠️ Be extremely careful with rm -rf.
There is normally no recycle bin involved.
13. Removing Directories
rmdir
Removes an empty directory.
rmdir test
If the directory contains files, rmdir normally fails.
For a directory and its contents:
rm -r test
14. File Information
file
Identifies the type of a file.
file example.txt
Example:
ASCII text
Another example:
file image.png
might report PNG image information.
stat
Displays detailed file information.
stat file.txt
It can show:
- size
- permissions
- inode
- owner
- timestamps
- links
15. Disk Usage
du
Shows disk usage of files/directories.
du file.txt
Human-readable:
du -h file.txt
Directory:
du -sh Documents/
Example:
250M Documents/
16. Filesystem Free Space
df
Shows filesystem disk-space usage.
df
Human-readable:
df -h
Typical:
Filesystem Size Used Avail Use% /dev/sda1 100G 60G 35G 64%
df vs du
| Command | Purpose |
|---|---|
df | Filesystem free/used space |
du | Space used by files/directories |
Memory trick:
df = Disk Free
du = Disk Usage
17. Finding Files
find
Very powerful command.
Basic:
find . -name "file.txt"
Search from current directory.
Search entire filesystem:
find / -name "file.txt"
This may produce permission errors or take significant time.
Find directories
find . -type d -name "project"
Find files
find . -type f -name "*.py"
Find by size
find . -type f -size +100M
18. locate
Searches a prebuilt file database.
locate file.txt
It is usually faster than scanning the filesystem with find, but results depend on the database being up to date.
19. Searching Text
grep
Searches for text patterns.
grep "hello" file.txt
Example:
hello world hello Linux
Ignore case
grep -i "hello" file.txt
Search recursively
grep -r "password" project/
Show line numbers
grep -n "hello" file.txt
Combine options
grep -rin "error" /var/log/
20. which
Shows the executable found through your PATH.
which python
Example:
/usr/bin/python
21. whereis
Searches for binary, source, and manual locations associated with a command.
whereis python
22. type
Shows how the shell interprets a command.
type ls
It may report that ls is an alias, function, builtin, or external command.
Very useful when debugging shell behavior.
23. Permissions
chmod
Changes file permissions.
Example:
chmod +x script.sh
Makes the script executable for applicable users according to the resulting permission set.
24. Numeric Permissions
Permissions use:
r = 4 w = 2 x = 1
Therefore:
rwx = 7 rw- = 6 r-x = 5 r-- = 4
Example:
chmod 755 script.sh
Means:
Owner → rwx → 7 Group → r-x → 5 Others → r-x → 5
So:
rwxr-xr-x
25. chown
Changes file ownership.
sudo chown user file.txt
Change owner and group:
sudo chown user:group file.txt
For a directory tree:
sudo chown -R user:group project/
26. chgrp
Changes group ownership.
chgrp developers file.txt
27. sudo
Runs a command with elevated privileges if the user is authorized.
Example:
sudo apt update
Another:
sudo systemctl restart ssh
Important:
sudodoes not automatically mean “become root permanently”; it normally executes the specified command with elevated privileges.
28. User Information Commands
whoami
Shows current username.
whoami
Example:
uday
id
Shows user and group IDs.
id
Example information:
uid=1000(uday) gid=1000(uday) groups=...
who
Shows logged-in users.
who
w
Shows logged-in users and what they are doing.
w
29. Process Commands
ps
Shows processes.
ps
More detailed:
ps aux
Another common format:
ps -ef
30. top
Real-time process monitor.
top
Shows:
- CPU usage
- memory usage
- processes
- PID
- load information
Exit:
q
31. htop
Interactive process viewer.
htop
It may need installation depending on the distribution.
32. kill
Sends a signal to a process.
kill PID
Example:
kill 1234
Graceful termination:
kill -TERM 1234
Forceful termination:
kill -KILL 1234
Use SIGKILL only when necessary because the process cannot catch it and perform normal cleanup.
33. pkill
Kills/signals processes based on name or other matching criteria.
Example:
pkill firefox
Use carefully because multiple matching processes can be affected.
34. jobs
Shows jobs started from the current shell.
jobs
35. Background and Foreground
Run a command in background:
command &
Example:
firefox &
Bring a job to foreground:
fg
Send current foreground job to background:
Ctrl + Z
Then:
bg
36. nice and renice
These commands influence process scheduling priority.
Run with a different nice value:
nice -n 10 command
Change an existing process:
renice 10 -p PID
Important:
Nice value influences scheduling priority; it is not the same thing as CPU affinity or a hard real-time priority.
37. System Information
uname
Displays system/kernel information.
uname -a
Example information includes:
- kernel name
- hostname
- kernel release
- architecture
hostname
Displays hostname:
hostname
uptime
Shows how long the system has been running.
uptime
It can also show load averages.
free
Shows memory usage.
free -h
38. Date and Time
date
Example:
Mon Oct 5 20:00:00 IST 2026
The exact output depends on system time zone and configuration.
39. History
Shows previously executed shell commands.
history
Run a previous command:
!100
where 100 is a history entry number.
Search interactively in many shells:
Ctrl + R
40. Clearing Terminal
clear
Shortcut:
Ctrl + L
41. Echo
Displays text.
echo "Hello Linux"
Can also display variables:
echo $HOME
42. Environment Variables
Show one variable:
echo $PATH
Show many environment variables:
env
or:
printenv
Common variables:
HOME PATH USER SHELL PWD
43. export
Sets/exports an environment variable for child processes.
export NAME="Uday"
Then:
echo $NAME
Output:
Uday
44. Pipes
The pipe:
|
passes the output of one command as input to another.
Example:
ls | grep ".txt"
Flow:
ls ↓ Output ↓ grep ↓ Filtered output
Another example:
ps aux | grep firefox
45. Output Redirection
>
Writes output to a file, replacing/truncating existing content.
echo "Hello" > file.txt
>>
Appends output.
echo "Second line" >> file.txt
46. Input Redirection
<
Uses a file as standard input.
command < input.txt
47. Error Redirection
Standard error is file descriptor:
2
Redirect errors:
command 2> error.txt
Append errors:
command 2>> error.txt
48. Redirect Output and Errors
command > output.txt 2> error.txt
Both go to separate files.
To combine them:
command > output.txt 2>&1
49. /dev/null
/dev/null discards data written to it.
Example:
command > /dev/null
Discard output and errors:
command > /dev/null 2>&1
Conceptually:
Program ↓ /dev/null ↓ Data discarded
50. tee
Displays output and simultaneously writes it to a file.
echo "Hello" | tee output.txt
Append:
echo "Hello" | tee -a output.txt
51. Text Processing Commands
Important commands:
grep sort uniq cut tr awk sed wc
sort
sort names.txt
Sorts lines.
uniq
Removes adjacent duplicate lines.
uniq names.txt
Usually:
sort names.txt | uniq
is used when you want to eliminate duplicates regardless of their original ordering.
wc
Counts lines, words, and bytes.
wc file.txt
Line count:
wc -l file.txt
Word count:
wc -w file.txt
cut
Extracts fields/characters.
Example:
cut -d: -f1 /etc/passwd
Here:
-d: → delimiter is : -f1 → first field
tr
Translates or deletes characters.
Example:
echo "hello" | tr 'a-z' 'A-Z'
Output:
HELLO
52. sed
Stream editor used for text transformations.
Example:
sed 's/old/new/g' file.txt
Conceptually:
old ↓ new
It is very powerful for automated text editing.
53. awk
Powerful text-processing language.
Example:
awk '{print $1}' file.txt
Prints the first whitespace-separated field of each line.
54. Compression
Linux supports several archive/compression tools.
tar
Create archive:
tar -cf backup.tar project/
Extract:
tar -xf backup.tar
Create gzip-compressed archive:
tar -czf backup.tar.gz project/
Extract:
tar -xzf backup.tar.gz
55. gzip
Compress:
gzip file.txt
Decompress:
gunzip file.txt.gz
56. zip and unzip
Create:
zip backup.zip file.txt
Extract:
unzip backup.zip
57. Networking Commands
ip
Modern Linux networking command.
Show interfaces:
ip addr
Show routes:
ip route
58. ping
Tests network reachability using ICMP echo requests in the usual case.
ping 8.8.8.8
or:
ping example.com
Stop:
Ctrl + C
59. ss
Displays socket/network connection information.
ss
Listening TCP/UDP sockets:
ss -tuln
60. curl
Transfers data using URLs/protocols.
Example:
curl https://example.com
Save to a file:
curl -o page.html https://example.com
It is widely used for:
- HTTP testing
- APIs
- downloading
- debugging web requests
61. wget
Downloads files from network locations.
wget https://example.com/file.zip
62. DNS Commands
dig
Queries DNS.
dig example.com
Specific record:
dig example.com A
nslookup
Another DNS lookup utility:
nslookup example.com
63. traceroute
Shows the network path toward a destination.
traceroute example.com
On some systems it may need installation.
64. ssh
Secure Shell provides remote command-line access.
ssh user@server
Example:
ssh uday@192.168.1.10
Conceptually:
Your PC ↓ SSH ↓ Remote Linux Server
65. scp
Securely copies files using SSH.
Copy local → remote:
scp file.txt user@server:/home/user/
Remote → local:
scp user@server:/home/user/file.txt .
66. rsync
Efficiently synchronizes files/directories.
Example:
rsync -av project/ backup/
Remote example:
rsync -av project/ user@server:/home/user/project/
67. Storage Commands
lsblk
Lists block devices.
lsblk
Example concept:
sda ├── sda1 └── sda2 nvme0n1 ├── nvme0n1p1 └── nvme0n1p2
blkid
Shows block-device attributes such as UUID and filesystem type.
sudo blkid
mount
Mounts a filesystem.
Conceptually:
sudo mount /dev/sdb1 /mnt
Then:
/dev/sdb1 ↓ /mnt
umount
Unmount:
sudo umount /mnt
68. lsusb
Lists USB devices.
lsusb
Useful for troubleshooting USB hardware.
69. lspci
Lists PCI devices.
lspci
Show associated kernel drivers:
lspci -k
Useful for:
- Wi-Fi adapters
- graphics devices
- Ethernet controllers
- other PCI hardware
70. dmesg
Displays kernel messages.
dmesg
Useful when troubleshooting:
- USB devices
- drivers
- storage
- hardware detection
- kernel events
On some systems, ordinary users may need appropriate permissions to read all kernel messages.
71. Services
On a system using systemd:
Check status:
systemctl status ssh
Start:
sudo systemctl start ssh
Stop:
sudo systemctl stop ssh
Restart:
sudo systemctl restart ssh
Enable at boot:
sudo systemctl enable ssh
Disable:
sudo systemctl disable ssh
72. Package Management — Debian/Kali/Ubuntu
Update package lists:
sudo apt update
Upgrade packages:
sudo apt upgrade
Install:
sudo apt install nmap
Remove:
sudo apt remove nmap
Search:
apt search nmap
Show package information:
apt show nmap
73. apt update vs apt upgrade
Very important:
apt update ↓ Refresh package information apt upgrade ↓ Actually upgrade installed packages
So:
sudo apt update sudo apt upgrade
is a common sequence.
74. File Permissions — Practical Example
Create:
touch script.sh
Check:
ls -l script.sh
Make executable:
chmod +x script.sh
Run:
./script.sh
The ./ tells the shell to execute the file from the current directory.
75. Shell Variables
Set:
name="Uday"
Use:
echo "$name"
Output:
Uday
Important:
name="Uday"
not:
name = "Uday"
because shell assignment syntax does not allow spaces around =.
76. Command Chaining
;
Runs commands sequentially regardless of whether the previous one succeeds.
command1 ; command2
&&
Runs the second command only if the first succeeds.
command1 && command2
Example:
mkdir test && cd test
||
Runs the second command if the first fails.
command1 || command2
Example:
ping -c 1 example.com && echo "Reachable" || echo "Failed"
77. Wildcards
Linux shells support patterns.
*
Matches many characters.
ls *.txt
Matches:
a.txt hello.txt notes.txt
?
Matches one character.
ls file?.txt
Could match:
file1.txt fileA.txt
Character classes
ls file[123].txt
78. Command History and Keyboard Shortcuts
Important shortcuts:
| Shortcut | Function |
|---|---|
Ctrl + C | Interrupt current command |
Ctrl + Z | Suspend foreground process |
Ctrl + D | EOF / often exits shell |
Ctrl + L | Clear terminal view |
Ctrl + R | Search command history |
Tab | Auto-completion |
↑ | Previous command |
↓ | Next command |
79. Standard Streams
Linux programs commonly use three standard file descriptors:
0 → stdin 1 → stdout 2 → stderr
Diagram:
Program / | \ / | \ stdin stdout stderr 0 1 2
Example:
command > output.txt
redirects stdout.
command 2> error.txt
redirects stderr.
80. Important Command Categories
For exam revision:
| Category | Commands |
|---|---|
| Navigation | pwd, cd, ls |
| Files | touch, cat, cp, mv, rm |
| Directories | mkdir, rmdir |
| Search | find, locate |
| Text search | grep |
| Text processing | awk, sed, cut, sort, uniq, tr |
| Permissions | chmod, chown, chgrp |
| Users | whoami, id, who, w |
| Processes | ps, top, htop, kill, pkill |
| System | uname, hostname, uptime, free |
| Storage | df, du, lsblk, blkid |
| Networking | ip, ping, ss, curl, wget |
| DNS | dig, nslookup |
| Remote | ssh, scp, rsync |
| Packages | apt, dnf, pacman |
| Services | systemctl |
| Hardware | lsusb, lspci, dmesg |
| Archive | tar, gzip, zip, unzip |
| Help | man, help, --help, whatis, apropos |
81. Most Important Commands to Memorize
If you're preparing for an exam/interview, start with these:
pwd ls cd mkdir rmdir touch cat cp mv rm find grep chmod chown sudo ps top kill df du free ip ping ss curl ssh scp tar apt systemctl man
🧠 Final Linux Commands Memory Map
LINUX COMMANDS │ ┌──────────────────┼──────────────────┐ ↓ ↓ ↓ NAVIGATION FILES PROCESSES pwd ls ps cd touch top ls cat kill cp jobs mv rm │ │ │ ├──────────────────┼──────────────────┤ ↓ ↓ ↓ SEARCH SECURITY NETWORK find chmod ip grep chown ping locate sudo ss curl ssh │ ├───────────────┬───────────────────┐ ↓ ↓ ↓ STORAGE PACKAGE SERVICE df apt systemctl du lsblk mount
🧠 Super-short memory trick
Navigate → Create → Read → Copy → Move → Delete → Search → Protect → Process → Network → Manage
And the most important shell concepts:
| → pipe > → overwrite output >> → append output < → input 2> → error output && → run next if success || → run next if failure & → background