🐧 Mastering the Linux Command Line
 |
| Kali Linux |
Your Complete Guide: From Beginner to Confident User
35+
Essential Commands Covered with Real Examples
Whether you're a developer, system administrator, or just curious about Linux, mastering the command line is an essential skill that will dramatically boost your productivity. This comprehensive guide breaks down the most critical Linux commands into logical categories with real, copy-paste examples you can try right now.
We'll progress from basic file navigation to advanced system administration and network analysis, giving you a clear path to command-line proficiency.
📁 Section 1: The Core Workflow - Navigation Essentials
Every Linux session follows a natural flow: figure out where you are, see what's around you, move to where you need to be, and then work with files. Let's master each step.
pwd
→
ls
→
cd
→
Work!
pwd - Print Working Directory
Always know exactly where you are in the filesystem:
$ pwd
/home/john/projects/webapp
ls - List Directory Contents
See what files and folders exist in your current location:
$ ls
Documents Downloads Pictures Videos
$ ls -la # Detailed view with hidden files
total 32
drwxr-xr-x 5 john john 4096 Feb 23 10:30 .
drwxr-xr-x 3 root root 4096 Feb 20 09:15 ..
-rw-r--r-- 1 john john 220 Feb 20 09:15 .bashrc
drwxr-xr-x 2 john john 4096 Feb 23 10:30 Documents
$ ls -lh /var/log # Human-readable sizes in specific directory
cd - Change Directory
Navigate through the filesystem like a pro:
$ cd Documents # Enter a subdirectory
$ cd /var/log # Go to absolute path
$ cd .. # Go up one level
$ cd ~ # Go to home directory
$ cd - # Go back to previous directory
Creating Files and Directories
$ mkdir my_project # Create a directory
$ mkdir -p projects/web/css # Create nested directories
$ touch index.html # Create an empty file
$ touch file1.txt file2.txt # Create multiple files
Managing Files: Copy, Move, Delete
$ cp file.txt backup.txt # Copy a file
$ cp -r folder/ folder_backup/ # Copy directory recursively
$ mv oldname.txt newname.txt # Rename a file
$ mv file.txt ~/Documents/ # Move file to another location
$ rm unwanted.txt # Delete a file
$ rm -r old_folder/ # Delete directory and contents
⚠️ Warning: The rm command permanently deletes files with no recycle bin! Always double-check before using rm -r or rm -rf.
🔍 Section 2: Finding Your Way with Files
Linux offers incredibly powerful tools for searching within files and locating them across your entire system. Master grep and find to become truly efficient.
grep - Search Inside Files
Find text patterns within files - arguably the most useful command for developers:
$ grep "error" /var/log/syslog
Feb 23 10:15:32 server kernel: [ERROR] Disk read failure
$ grep -i "warning" app.log # Case-insensitive search
$ grep -r "TODO" ./src/ # Search recursively in directory
./src/main.js:42: // TODO: Add error handling
./src/utils.js:15: // TODO: Optimize this function
$ grep -n "function" script.js # Show line numbers
5:function calculateTotal() {
12:function validateInput(data) {
$ grep -c "GET" access.log # Count matches
1523
find - Locate Files by Name, Type, or Properties
$ find . -name "*.txt" # Find all .txt files
./notes.txt
./docs/readme.txt
$ find /home -name "config*" # Find files starting with "config"
$ find . -type d -name "test*" # Find directories only
$ find . -size +100M # Find files larger than 100MB
$ find . -mtime -7 # Files modified in last 7 days
$ find . -name "*.log" -delete # Find and delete (use carefully!)
Reading File Contents
$ cat config.txt # Display entire file
$ head -20 largefile.log # First 20 lines
$ tail -50 /var/log/syslog # Last 50 lines
$ tail -f /var/log/nginx/access.log # Follow log in real-time
$ less hugefile.txt # Paginated viewing (q to quit)
💡 Pro Tip: Combine commands with pipes! cat access.log | grep "404" | wc -l counts all 404 errors.
🔐 Section 3: Security & Permissions
Understanding file permissions is absolutely critical for system security. Every file in Linux has three permission sets: for the owner, the group, and others.
Understanding Permission Numbers
| Permission |
Symbol |
Numeric Value |
Meaning |
| Read |
r |
4 |
View file contents / List directory |
| Write |
w |
2 |
Modify file / Create files in directory |
| Execute |
x |
1 |
Run as program / Enter directory |
Common Permission Combinations
7 = 4+2+1 = rwx (read, write, execute - full access)
6 = 4+2 = rw- (read, write)
5 = 4+1 = r-x (read, execute)
4 = 4 = r-- (read only)
0 = 0 = --- (no access)
chmod - Change Permissions
$ chmod 755 script.sh
# Owner: rwx (7), Group: r-x (5), Others: r-x (5)
# Perfect for executable scripts
$ chmod 644 document.txt
# Owner: rw- (6), Group: r-- (4), Others: r-- (4)
# Standard for regular files
$ chmod 700 private_folder/
# Only owner has access - completely private
$ chmod +x deploy.sh
# Quick way to add execute permission
chown - Change Ownership
$ sudo chown john file.txt # Change owner
$ sudo chown john:developers file.txt # Change owner and group
$ sudo chown -R www-data:www-data /var/www/ # Recursive
📊 Section 4: System Monitoring
Keep your finger on the pulse of your system with these essential monitoring commands.
top / htop - Real-Time Process Monitoring
$ top
top - 14:32:15 up 45 days, 3:22, 2 users, load average: 0.15, 0.10, 0.08
Tasks: 142 total, 1 running, 141 sleeping, 0 stopped
%Cpu(s): 2.3 us, 1.0 sy, 0.0 ni, 96.5 id, 0.2 wa
MiB Mem : 7976.4 total, 1234.5 free, 4521.2 used, 2220.7 buff/cache
PID USER PR NI VIRT RES SHR S %CPU %MEM COMMAND
1234 mysql 20 0 1256932 524288 12340 S 5.2 6.4 mysqld
5678 www-data 20 0 456789 123456 8765 S 2.1 1.5 apache2
$ htop # More visual, interactive (install first)
ps - Process Snapshot
$ ps aux # View all processes
$ ps aux | grep nginx # Find specific process
root 1234 0.0 0.1 12345 6789 ? Ss 10:00 0:00 nginx: master
www-data 1235 0.0 0.2 23456 9876 ? S 10:00 0:02 nginx: worker
$ ps -ef --forest # Show process tree
df - Disk Space Usage
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 45G 50G 47% /
/dev/sda2 500G 200G 275G 42% /home
/dev/sdb1 1.0T 750G 250G 75% /data
du - Directory Size
$ du -sh * # Size of each item in current dir
4.0K config.txt
256M downloads
1.2G videos
$ du -sh /var/log/ # Total size of a directory
2.3G /var/log/
$ du -h --max-depth=1 /home/ # One level deep
Other Useful Monitoring Commands
$ uptime
14:35:22 up 45 days, 3:25, 2 users, load average: 0.15, 0.10, 0.08
$ free -h # Memory usage
total used free shared buff/cache available
Mem: 7.8Gi 4.4Gi 1.2Gi 234Mi 2.2Gi 2.9Gi
Swap: 2.0Gi 0.5Gi 1.5Gi
$ whoami # Current user
john
$ w # Who is logged in and what they're doing
🌐 Section 5: Networking Commands
These commands are essential for troubleshooting connectivity issues and understanding your network configuration.
ping - Test Connectivity
$ ping google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from lax17s55-in-f14.1e100.net: icmp_seq=1 ttl=117 time=12.3 ms
64 bytes from lax17s55-in-f14.1e100.net: icmp_seq=2 ttl=117 time=11.8 ms
$ ping -c 4 192.168.1.1 # Ping 4 times only
ip / ifconfig - Network Configuration
$ ip addr show # Modern way to see IP addresses
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
inet6 fe80::1234:5678:90ab:cdef/64 scope link
$ ip route show # View routing table
$ ifconfig # Legacy command (still widely used)
curl / wget - Download & Test URLs
$ curl https://api.github.com # Fetch URL content
$ curl -I https://google.com # Headers only
HTTP/2 200
content-type: text/html; charset=ISO-8859-1
date: Sun, 23 Feb 2026 14:30:00 GMT
$ wget https://example.com/file.zip # Download a file
$ wget -O custom-name.zip https://example.com/file.zip
netstat / ss - Network Connections
$ ss -tuln # Show listening ports
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:443 0.0.0.0:*
$ netstat -tulpn # Legacy alternative with process info
traceroute - Path Analysis
$ traceroute google.com
1 router.local (192.168.1.1) 1.234 ms
2 isp-gateway (10.0.0.1) 8.567 ms
3 core-router.isp.net (72.14.215.85) 15.234 ms
...
📦 Section 6: Package Management
Installing software in Linux is handled by package managers. The commands differ based on your distribution, but the concepts are the same.
🟠 Debian / Ubuntu (apt)
sudo apt update
# Refresh package lists
sudo apt upgrade
# Upgrade all packages
sudo apt install nginx
# Install a package
sudo apt remove nginx
# Remove a package
apt search "web server"
# Search for packages
🔵 RHEL / Fedora (dnf)
sudo dnf check-update
# Check for updates
sudo dnf upgrade
# Upgrade all packages
sudo dnf install nginx
# Install a package
sudo dnf remove nginx
# Remove a package
dnf search "web server"
# Search for packages
💡 Pro Tip: Always run apt update (or dnf check-update) before installing new packages to ensure you get the latest versions!
🛡️ Section 7: Security & Reconnaissance
These commands serve dual purposes: everyday troubleshooting and security analysis. Understanding them is crucial for both system administrators and security professionals.
nmap - Network Scanner
$ nmap 192.168.1.1 # Scan single host
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
$ nmap -sV 192.168.1.1 # Detect service versions
$ nmap 192.168.1.0/24 # Scan entire subnet
ssh - Secure Shell
$ ssh user@server.com # Connect to remote server
$ ssh -p 2222 user@server.com # Connect on custom port
$ ssh-keygen -t ed25519 # Generate SSH key pair
$ ssh-copy-id user@server.com # Copy public key to server
ufw - Simple Firewall
$ sudo ufw status # Check firewall status
$ sudo ufw enable # Enable firewall
$ sudo ufw allow 22 # Allow SSH
$ sudo ufw allow 80,443/tcp # Allow web traffic
$ sudo ufw deny from 10.0.0.5 # Block specific IP
🎯 Bonus: Power User Tips
Command History & Shortcuts
$ history # View command history
$ !! # Repeat last command
$ !ssh # Repeat last command starting with "ssh"
$ Ctrl + R # Search command history
Useful Shortcuts
- Ctrl + C - Cancel current command
- Ctrl + Z - Suspend current process
- Ctrl + L - Clear screen
- Tab - Auto-complete files and commands
- ↑ / ↓ - Navigate command history
Combining Commands
$ command1 && command2 # Run command2 only if command1 succeeds
$ command1 || command2 # Run command2 only if command1 fails
$ command1 ; command2 # Run both regardless of result
$ command1 | command2 # Pipe output to next command
🚀 Your Journey Begins Now!
Congratulations! You've now covered 35+ essential Linux commands that will serve you well in almost any situation. Remember:
- Practice daily - The command line becomes second nature with use
- Use man command - Every command has a manual page
- Don't fear mistakes - Just be careful with rm and sudo!
- Build muscle memory - Speed comes from repetition
🐧 The penguin awaits. Happy exploring! 🐧
Comments
Post a Comment
Your opinion matters, your voice makes us proud and happy. Your words are our motivation.