Complete Ubuntu Linux commands cheat sheet for system administrators and developers. All essential Ubuntu commands organized by category with copy-paste ready examples. Works with Ubuntu 20.04 LTS, Ubuntu 22.04 LTS, Ubuntu 24.04 LTS, and newer versions.
📦 Package Management (APT) | 📦 Snap Packages | 📁 File Operations | 👤 User Management
🌐 Networking | 🔥 Firewall (UFW) | 💾 Disk Management | 📊 System Monitoring
🔒 Permissions | 🔄 Process Management | 📋 Service Management
📦 Package Management (APT)
Update & Upgrade
# Update package lists
sudo apt update
# Upgrade all packages
sudo apt upgrade
# Full upgrade (handles dependencies)
sudo apt full-upgrade
# Dist upgrade
sudo apt dist-upgrade
# Upgrade to new Ubuntu version
sudo do-release-upgrade
Install & Remove Packages
# Install package
sudo apt install package-name
# Install multiple packages
sudo apt install package1 package2 package3
# Install without prompts
sudo apt install -y package-name
# Install specific version
sudo apt install package-name=version
# Reinstall package
sudo apt install --reinstall package-name
# Remove package (keep config files)
sudo apt remove package-name
# Remove package and config files
sudo apt purge package-name
# Remove unused dependencies
sudo apt autoremove
# Remove unused packages and clean cache
sudo apt autoremove --purge && sudo apt clean
Search & Information
# Search for package
apt search keyword
# Show package information
apt show package-name
# List installed packages
apt list --installed
# List upgradable packages
apt list --upgradable
# Check package version
apt policy package-name
# Show package dependencies
apt depends package-name
# Show reverse dependencies
apt rdepends package-name
PPAs (Personal Package Archives)
# Add PPA
sudo add-apt-repository ppa:user/ppa-name
sudo apt update
# Remove PPA
sudo add-apt-repository --remove ppa:user/ppa-name
# List PPAs
ls /etc/apt/sources.list.d/
Use
apt instead of apt-get for cleaner output and progress bars. apt is the modern way for Ubuntu package management.
📦 Snap Package Management
# Find snap packages
snap find keyword
# Install snap package
sudo snap install package-name
# Install from specific channel
sudo snap install package-name --classic
sudo snap install package-name --beta
# List installed snaps
snap list
# Update all snaps
sudo snap refresh
# Update specific snap
sudo snap refresh package-name
# Remove snap
sudo snap remove package-name
# Show snap info
snap info package-name
# View snap logs
snap logs package-name
# Disable/Enable snap
sudo snap disable package-name
sudo snap enable package-name
📁 File & Directory Operations
Navigation & Listing
# List files
ls
ls -la # Detailed list with hidden files
ls -lh # Human-readable file sizes
ls -ltr # Sort by time, oldest first
ls -lS # Sort by size
# Change directory
cd /path/to/dir
cd .. # Parent directory
cd ~ # Home directory
cd - # Previous directory
# Print working directory
pwd
# Show directory tree
tree
tree -L 2 # Limit depth to 2 levels
tree -d # Directories only
Create, Copy, Move, Delete
# Create directory
mkdir dirname
mkdir -p path/to/nested/dir
# Create file
touch filename
# Copy files
cp source dest
cp -r source/ dest/ # Recursive (directories)
cp -a source/ dest/ # Archive mode (preserve all)
cp -v source dest # Verbose output
# Move/Rename
mv source dest
mv oldname newname
mv -v source dest # Verbose
# Remove files/directories
rm filename
rm -r dirname # Recursive
rm -rf dirname # Force recursive (dangerous!)
rm -i filename # Interactive (ask before delete)
View & Edit Files
# View file content
cat filename
less filename # Paginated view
more filename # Paginated view (simple)
head filename # First 10 lines
head -n 20 filename # First 20 lines
tail filename # Last 10 lines
tail -f filename # Follow file (live updates)
tail -n 50 filename # Last 50 lines
# Edit files
nano filename
vim filename
gedit filename # GUI editor (desktop)
Search & Find
# Find files by name
find /path -name "*.txt"
find . -type f -name "file*"
find . -type d -name "dirname"
find / -name filename 2>/dev/null
# Find files by size
find . -size +100M # Larger than 100MB
find . -size -1M # Smaller than 1MB
# Find and execute
find . -name "*.log" -exec rm {} \;
find . -type f -mtime +30 -delete # Delete files older than 30 days
# Search in files (grep)
grep "pattern" filename
grep -r "pattern" /path # Recursive
grep -i "pattern" file # Case insensitive
grep -n "pattern" file # Show line numbers
grep -v "pattern" file # Invert match (exclude)
# Locate (fast find)
sudo updatedb # Update locate database
locate filename
👤 User & Group Management
User Operations
# Add user
sudo adduser username
sudo useradd username
# Delete user
sudo deluser username
sudo userdel username
sudo userdel -r username # Remove home directory too
# Change password
sudo passwd username
passwd # Change own password
# Modify user
sudo usermod -aG groupname username # Add to group
sudo usermod -aG sudo username # Add to sudo group
sudo usermod -l newname oldname # Rename user
sudo usermod -s /bin/bash username # Change shell
# List all users
cat /etc/passwd
cut -d: -f1 /etc/passwd
# Switch user
su username
su - # Switch to root
sudo -i # Root shell
sudo command # Run command as root
Group Operations
# Add group
sudo addgroup groupname
sudo groupadd groupname
# Delete group
sudo delgroup groupname
sudo groupdel groupname
# Show user groups
groups username
id username
# List all groups
cat /etc/group
🔒 Permissions & Ownership
# Change permissions (numeric)
chmod 644 file # rw-r--r--
chmod 755 file # rwxr-xr-x
chmod 600 file # rw-------
chmod -R 755 dir # Recursive
# Change permissions (symbolic)
chmod u+x file # Add execute for user
chmod g-w file # Remove write for group
chmod o=r file # Set read-only for others
chmod a+r file # Add read for all
# Change ownership
sudo chown user:group file
sudo chown -R user:group dir # Recursive
sudo chown user file # Change user only
sudo chgrp group file # Change group only
# View permissions
ls -l filename
stat filename
# Access Control Lists (ACL)
getfacl filename
setfacl -m u:username:rw file
Never run
chmod 777 on production systems! This gives full permissions to everyone and creates security vulnerabilities.
🌐 Networking Commands
Network Configuration
# Show network interfaces
ip addr show
ip a
ifconfig # Legacy command
# Show routing table
ip route show
route -n
# Configure static IP (netplan - Ubuntu 18.04+)
sudo nano /etc/netplan/01-netcfg.yaml
sudo netplan apply
# Show network statistics
netstat -tulpn
ss -tulpn # Modern alternative
ss -s # Summary statistics
# Test connectivity
ping example.com
ping -c 4 example.com # Send 4 packets
ping6 example.com # IPv6 ping
# Trace route
traceroute example.com
mtr example.com # Interactive traceroute
# DNS lookup
nslookup example.com
dig example.com
host example.com
resolvectl status # DNS resolver status
Download & Transfer
# Download files
wget https://example.com/file.zip
wget -c url # Continue interrupted download
wget -O output.zip url # Save with custom name
curl -O https://example.com/file.zip
curl -L url # Follow redirects
curl -o output.zip url # Save with custom name
# Transfer files (SCP)
scp file.txt user@host:/path/
scp user@host:/path/file.txt .
scp -r dir/ user@host:/path/
scp -P 2222 file user@host:/path/ # Custom port
# Rsync (sync files)
rsync -avz source/ dest/
rsync -avz source/ user@host:/path/
rsync -avz --delete source/ dest/ # Delete extra files
🔥 Firewall (UFW)
# Enable/Disable UFW
sudo ufw enable
sudo ufw disable
# Check status
sudo ufw status
sudo ufw status verbose
sudo ufw status numbered
# Allow/Deny ports
sudo ufw allow 22 # Allow SSH
sudo ufw allow 80/tcp # Allow HTTP
sudo ufw allow 443/tcp # Allow HTTPS
sudo ufw deny 3306 # Deny MySQL
sudo ufw allow 8000:8100/tcp # Allow port range
# Allow specific services
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
# Allow from specific IP
sudo ufw allow from 192.168.1.100
sudo ufw allow from 192.168.1.0/24
# Allow from IP to specific port
sudo ufw allow from 192.168.1.100 to any port 22
# Delete rule
sudo ufw delete allow 80
sudo ufw delete 1 # Delete by number
# Reset firewall
sudo ufw reset
# Set default policies
sudo ufw default deny incoming
sudo ufw default allow outgoing
💾 Disk & Storage Management
Disk Usage
# Show disk space
df -h # Human-readable
df -i # Inode usage
df -T # Show filesystem type
# Show directory sizes
du -h /path
du -sh /path # Summary only
du -h --max-depth=1 # One level deep
du -sh /* # Size of root directories
# Show largest directories
du -h / | sort -rh | head -20
ncdu / # Interactive disk usage (install first)
# Check disk usage by file type
find . -name "*.log" -exec du -ch {} + | tail -1
Mount & Unmount
# Show mounted filesystems
mount
df -h
findmnt # Tree view of mounts
# Mount filesystem
sudo mount /dev/sda1 /mnt
sudo mount -t ext4 /dev/sda1 /mnt
# Unmount
sudo umount /mnt
sudo umount /dev/sda1
sudo umount -l /mnt # Lazy unmount
# Mount all in fstab
sudo mount -a
# Check fstab
cat /etc/fstab
# Auto-mount USB devices
ls /media/$USER/
Disk Partitioning
# List disks
lsblk
lsblk -f # Show filesystems
sudo fdisk -l
sudo parted -l
# Partition disk (interactive)
sudo fdisk /dev/sda
sudo parted /dev/sda
# Format partition
sudo mkfs.ext4 /dev/sda1
sudo mkfs.xfs /dev/sda1
sudo mkfs.ntfs /dev/sda1
# Check filesystem
sudo fsck /dev/sda1
sudo e2fsck /dev/sda1
# Disk health (SMART)
sudo smartctl -a /dev/sda
sudo smartctl -H /dev/sda # Health status
🔄 Process Management
# List processes
ps aux
ps -ef
top # Interactive
htop # Better interactive (install first)
# Find process
ps aux | grep processname
pgrep processname
pidof processname
# Kill process
kill PID
kill -9 PID # Force kill
killall processname
pkill processname
pkill -u username # Kill all processes by user
# Process priority
nice -n 10 command # Start with priority
renice -n 5 -p PID # Change priority
# Background processes
command & # Run in background
nohup command & # Run after logout
jobs # List background jobs
fg %1 # Bring job 1 to foreground
bg %1 # Resume job 1 in background
# Process tree
pstree
pstree -p # Show PIDs
📋 Service Management (systemd)
# Start/Stop services
sudo systemctl start servicename
sudo systemctl stop servicename
sudo systemctl restart servicename
sudo systemctl reload servicename
# Enable/Disable services (autostart)
sudo systemctl enable servicename
sudo systemctl disable servicename
sudo systemctl enable --now servicename # Enable and start
# Check service status
sudo systemctl status servicename
systemctl is-active servicename
systemctl is-enabled servicename
systemctl is-failed servicename
# List all services
systemctl list-units --type=service
systemctl list-units --type=service --state=running
systemctl list-unit-files --type=service
# View logs
journalctl -u servicename
journalctl -u servicename -f # Follow logs
journalctl -u servicename --since today
journalctl -u servicename --since "1 hour ago"
journalctl -xe # Recent errors
# Reload systemd
sudo systemctl daemon-reload
📊 System Monitoring & Information
System Information
# System info
uname -a # Kernel info
hostnamectl # Hostname and OS info
lsb_release -a # Ubuntu version
cat /etc/os-release # OS info
# Hardware info
lscpu # CPU info
lsmem # Memory info
lshw # All hardware
lshw -short # Brief hardware list
sudo dmidecode # DMI/SMBIOS info
lspci # PCI devices
lsusb # USB devices
lsblk # Block devices
# Ubuntu version
cat /etc/issue
lsb_release -d
Resource Monitoring
# CPU & Memory
top
htop
free -h # Memory usage
free -m # Memory in MB
vmstat 1 # Virtual memory stats
mpstat # CPU statistics
# Disk I/O
iostat
iostat -x 1 # Extended stats
iotop # Interactive I/O monitor
# Network traffic
iftop
nethogs
nload
vnstat # Network statistics
# Load average
uptime
w
tload # Load average graph
# System monitoring dashboard
glances # All-in-one monitor (install first)
🔍 Log Files
# System logs (systemd)
journalctl
journalctl -f # Follow logs
journalctl -b # Boot logs
journalctl -p err # Errors only
journalctl --since today
journalctl --since "2025-01-01"
# Legacy log files
tail -f /var/log/syslog
tail -f /var/log/auth.log
tail -f /var/log/kern.log
# Application logs
tail -f /var/log/apache2/error.log
tail -f /var/log/nginx/error.log
tail -f /var/log/mysql/error.log
# Search logs
grep "error" /var/log/syslog
journalctl | grep "error"
# Clear journal logs
sudo journalctl --vacuum-time=7d # Keep 7 days
sudo journalctl --vacuum-size=500M # Keep 500MB
VPS Commander provides a visual interface for all Ubuntu server operations. No command line knowledge required!
→ Try VPS Commander Free
⚡ Quick Commands Reference
System Control
# Reboot system
sudo reboot
sudo systemctl reboot
# Shutdown
sudo shutdown now
sudo shutdown -h now
sudo poweroff
# Schedule shutdown
sudo shutdown -h +10 # Shutdown in 10 minutes
sudo shutdown -r 22:00 # Reboot at 10 PM
sudo shutdown -c # Cancel scheduled shutdown
Archive & Compression
# Tar archives
tar -czf archive.tar.gz /path # Create gzip archive
tar -xzf archive.tar.gz # Extract gzip archive
tar -cjf archive.tar.bz2 /path # Create bzip2 archive
tar -xjf archive.tar.bz2 # Extract bzip2 archive
tar -cJf archive.tar.xz /path # Create xz archive
tar -xJf archive.tar.xz # Extract xz archive
# View archive contents
tar -tzf archive.tar.gz
tar -tjf archive.tar.bz2
# Zip
zip -r archive.zip /path
unzip archive.zip
unzip -l archive.zip # List contents
# 7zip
7z a archive.7z /path
7z x archive.7z
Text Processing
# Cut, sort, unique
cut -d':' -f1 /etc/passwd
sort filename
sort -r filename # Reverse
sort -n filename # Numeric sort
uniq filename # Remove duplicates
sort filename | uniq -c # Count occurrences
# Word count
wc filename
wc -l filename # Line count
wc -w filename # Word count
wc -c filename # Byte count
# Sed (stream editor)
sed 's/old/new/' file
sed 's/old/new/g' file # Global replace
sed -i 's/old/new/g' file # In-place edit
# Awk
awk '{print $1}' file # Print first column
awk -F':' '{print $1}' /etc/passwd
awk '{sum+=$1} END {print sum}' file
🔧 Ubuntu-Specific Commands
Update Alternatives
# Configure default editor
sudo update-alternatives --config editor
# Configure default Java
sudo update-alternatives --config java
# Show all alternatives
update-alternatives --list
Ubuntu Advantage (Pro)
# Check Ubuntu Pro status
sudo pro status
# Attach Ubuntu Pro
sudo pro attach TOKEN
# Enable services
sudo pro enable esm-infra
sudo pro enable livepatch
Conclusion
This Ubuntu commands cheat sheet covers the most essential commands for managing Ubuntu Linux systems. Bookmark this page for quick reference when working with Ubuntu 20.04 LTS, Ubuntu 22.04 LTS, Ubuntu 24.04 LTS, or newer versions.
VPS Commander provides a visual interface for Ubuntu server management. No terminal commands needed.
Try it free: $2.99/month or $25/year
→ Get VPS Commander Now