Back to Home

🐧 Linux Commands

Master essential Linux commands for server management

File System Navigation

📁 List Contents

ls

List directory contents

📋 List All Files

ls -la

List all files with details

🔄 Change Directory

cd [dir]

Change to specified directory

📍 Print Directory

pwd

Print working directory

➕ Create Directory

mkdir [name]

Create a new directory

➖ Remove Directory

rmdir [name]

Remove empty directory

🌳 Directory Tree

tree

Display directory tree structure

File Operations

📄 Copy File

cp [src] [dest]

Copy files from source to destination

📂 Copy Directory

cp -r [src] [dest]

Copy directories recursively

✏️ Move/Rename

mv [src] [dest]

Move or rename files and directories

🗑️ Remove File

rm [file]

Remove a file

💥 Force Remove

rm -rf [dir]

Force remove directory and contents

📝 Create File

touch [file]

Create an empty file

📖 View File

cat [file]

Display file contents

📑 Paginated View

less [file]

View file with pagination

⬆️ First Lines

head -n [file]

Show first n lines of file

⬇️ Last Lines

tail -n [file]

Show last n lines of file

🔢 Count Lines

wc -l [file]

Count lines in a file

Text Editing with Vim/Nano

Nano (Beginner Friendly)

nano filename.txt # Open file in nano # Use Ctrl+O to save, Ctrl+X to exit

Vim (Power User)

vim filename.txt # Open file in vim # Normal Mode: i # Insert mode Esc # Back to normal :w # Save :q # Quit :wq # Save and quit :q! # Force quit dd # Delete line yy # Copy line p # Paste /search # Search n # Next search result

User & Permissions

whoami Display current user
sudo [cmd] Run command as root
adduser [name] Add new user
deluser [name] Remove user
passwd [user] Change user password
chmod [perm] [file] Change file permissions
chown [user:group] [file] Change file owner
# Permission examples: chmod 755 script.sh # rwxr-xr-x chmod +x script.sh # Add execute permission chmod -R 755 folder/ # Recursive permissions

System Monitoring

top View running processes
htop Interactive process viewer
ps aux List all processes
kill [pid] Kill process by ID
killall [name] Kill process by name
df -h Disk usage (human readable)
du -sh [dir] Directory size
free -h Memory usage
uptime System uptime

Networking

ip addr Show IP addresses
ip route Show routing table
ping [host] Ping a host
curl [url] Make HTTP request
wget [url] Download file
netstat -tulpn Show listening ports
ss -tulpn Socket statistics

Package Management

APT (Debian/Ubuntu)

sudo apt update # Update package list sudo apt upgrade # Upgrade packages sudo apt install [pkg] # Install package sudo apt remove [pkg] # Remove package sudo apt search [term] # Search packages apt list --installed # List installed

YUM/DNF (RHEL/CentOS/Fedora)

sudo dnf update # Update packages sudo dnf install [pkg] # Install package sudo dnf remove [pkg] # Remove package dnf search [term] # Search packages

Service Management

# Systemd (most modern distros) sudo systemctl start nginx # Start service sudo systemctl stop nginx # Stop service sudo systemctl restart nginx # Restart service sudo systemctl status nginx # Check status sudo systemctl enable nginx # Enable on boot sudo systemctl disable nginx # Disable on boot systemctl list-units --type=service # List services
# Init.d (older systems) sudo /etc/init.d/nginx start sudo /etc/init.d/nginx stop sudo /etc/init.d/nginx status

SSH & Remote Access

# Connect to remote server ssh user@hostname ssh -p 2222 user@hostname # Custom port ssh -i key.pem user@host # SSH key auth # Copy files over SSH scp file.txt user@host:/path/ scp -r folder/ user@host:/path/ # SSH key generation ssh-keygen -t rsa -b 4096

Archives & Compression

# Tar (archive) tar -cvf archive.tar dir/ # Create tar -xvf archive.tar # Extract tar -cvzf archive.tar.gz dir/ # Create gzip tar -xvzf archive.tar.gz # Extract gzip # Zip zip -r archive.zip dir/ unzip archive.zip

Useful Shortcuts

Ctrl + C

Cancel current command

Ctrl + Z

Suspend current command

Ctrl + L

Clear screen

Ctrl + A

Go to line start

Ctrl + E

Go to line end

Ctrl + U

Clear line before cursor

Ctrl + K

Clear line after cursor

Tab

Auto-complete

↑ / ↓

Command history

man [cmd]

Command manual

[cmd] --help

Command help

history

Command history