logo
Programming

Ubuntu CLI cheatsheet 2025

O

Ohidur Rahman Bappy

MAY 24, 2025

πŸš€ Ubuntu Server CLI Cheat Sheet 2024

Master the most essential Ubuntu CLI commands for everyday use. Whether you’re managing systems, files, packages, users, networks, or containers, this guide is your quick reference.


πŸ–₯️ System Management

System Info

uname -a                # All system info
hostnamectl             # Hostname and OS details
lscpu                   # CPU architecture info
timedatectl status      # System time

Monitoring

top                     # Real-time processes
htop                    # Enhanced top (install first)
df -h                   # Disk usage
free -m                 # Memory in MB
kill <PID>              # Kill a process

Jobs & Background

[command] &             # Run in background
jobs                    # View background jobs
fg <job>                # Bring job to foreground

Services

sudo systemctl start|stop|status|reload <service>
journalctl -f                           # Live logs
journalctl -u <unit>                   # Specific service logs

Scheduling

crontab -e              # Edit cron jobs
crontab -l              # List cron jobs

πŸ“ File Management

File Commands

ls                     # List files
touch file             # Create file
cp src dest            # Copy
mv src dest            # Move/rename
rm file                # Delete file

Directory Commands

pwd                    # Current dir
cd dir                 # Change dir
mkdir dir              # Create dir

Permissions & Ownership

chmod u+x file         # Make executable
chown user:group file  # Change ownership

Search & Find

find . -name "file"    # Find by name
grep "text" file       # Search text

Archive & Compress

tar -czvf archive.tar.gz files         # Compress
tar -xvf archive.tar.gz                # Extract

Text Editing

nano file              # Open in Nano
cat file               # Print content
less file              # View paginated
head file              # First lines
tail file              # Last lines
awk '{print}' file     # Line-by-line print

πŸ“¦ Package Management

APT (Advanced Packaging Tool)

sudo apt install pkg                    # Install
sudo apt install -f --reinstall pkg    # Reinstall broken
apt search pkg                         # Search
apt-cache policy pkg                   # Show versions
sudo apt update && sudo apt upgrade    # Update & upgrade
sudo apt remove|purge pkg              # Remove

Snap

snap find pkg              # Search Snap
sudo snap install pkg      # Install
sudo snap remove pkg       # Remove
sudo snap refresh          # Update all
snap list                  # List installed
snap info pkg              # Info

πŸ‘₯ User & Group Management

Users

w                         # Who's logged in
sudo adduser user         # Add user
sudo deluser user         # Delete user
sudo passwd user          # Change password
su user                   # Switch user
sudo passwd -l|-u user    # Lock/unlock user

Groups

id user                   # User IDs
groups user               # User’s groups
sudo addgroup group       # Add group
sudo delgroup group       # Delete group

🌐 Networking

Interfaces & IPs

ip addr show              # IP info
ip -s link                # Stats
ss -l                     # Listening sockets
ping host                 # Ping

Netplan

cat /etc/netplan/*.yaml
sudo netplan try
sudo netplan apply

Firewall (UFW)

sudo ufw status|enable|disable
sudo ufw allow|deny port
sudo ufw delete allow|deny port

Remote Access

ssh user@host             # SSH
scp file user@host:path   # Secure copy

πŸ“¦ Containers with LXD

Setup

lxd init

Create Instances

lxc init ubuntu:22.04 name             # Create container
lxc launch ubuntu:24.04 name           # Start container
lxc launch ubuntu:22.04 name --vm      # Start VM

Manage Instances

lxc list|info|start|stop|delete name

Access & Files

lxc exec name -- command
lxc exec name -- bash
lxc console name
lxc file pull name/path localpath
lxc file push localpath name/path

Projects

lxc project create name
lxc project set name key=value
lxc project switch name

πŸ›‘οΈ Ubuntu Pro

Activation

sudo pro attach <token>

Services

sudo pro status
sudo pro enable|disable <service>

Security Add-ons

sudo pro enable esm-infra      # Infrastructure ESM
sudo pro enable esm-apps       # Apps ESM
sudo pro enable livepatch      # Kernel patch without reboot
sudo pro enable fips           # FIPS compliance

Other

sudo pro refresh               # Refresh config
sudo pro detach                # Remove Ubuntu Pro

πŸ“š Resources