Master essential Linux commands for server management
ls
List directory contents
ls -la
List all files with details
cd [dir]
Change to specified directory
pwd
Print working directory
mkdir [name]
Create a new directory
rmdir [name]
Remove empty directory
tree
Display directory tree structure
cp [src] [dest]
Copy files from source to destination
cp -r [src] [dest]
Copy directories recursively
mv [src] [dest]
Move or rename files and directories
rm [file]
Remove a file
rm -rf [dir]
Force remove directory and contents
touch [file]
Create an empty file
cat [file]
Display file contents
less [file]
View file with pagination
head -n [file]
Show first n lines of file
tail -n [file]
Show last n lines of file
wc -l [file]
Count lines in a file
nano filename.txt # Open file in nano
# Use Ctrl+O to save, Ctrl+X to exit
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
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
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 |
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 |
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
sudo dnf update # Update packages
sudo dnf install [pkg] # Install package
sudo dnf remove [pkg] # Remove package
dnf search [term] # Search packages
# 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
# 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
# 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
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