System
System information
# Displays all system information.
uname -a
# Shows current hostname and related details.
hostnamectl
# Lists CPU architecture information.
lscpu
# Shows system time.
timedatectl status
System monitoring and management
# Displays real-time system processes.
top
# An interactive process viewer (needs installation).
htop
# Shows disk usage in a human-readable format.
df -h
# Displays free and used memory in MB.
free -m
# Terminates a process.
kill <process id>
Running commands
# Runs command in the background.
[command] &
# Displays background commands.
jobs
# Brings command to the foreground.
fg <command number>
Service management
# Starts a service.
sudo systemctl start <service>
# Stops a service.
sudo systemctl stop <service>
# Checks the status of a service.
sudo systemctl status <service>
# Reloads a service’s configuration without interrupting its operation.
sudo systemctl reload <service>
# Follows the journal, showing new log messages in real time.
journalctl -f
# Displays logs for a specific systemd unit.
journalctl -u <unit_name>
Cron jobs and scheduling
# Edits cron jobs for the current user.
crontab -e
# Lists cron jobs for the current user.
crontab -l
Files
File management
# Lists files and directories.
ls
# Creates an empty file or updates the last accessed date.
touch <filename>
# Copies files from source to destination.
cp <source> <destination>
# Moves files or renames them.
mv <source> <destination>
# Deletes a file.
rm <filename>
Directory navigation
# Displays the current directory path.
pwd
# Changes the current directory.
cd <directory>
# Creates a new directory.
mkdir <dirname>
File permissions and ownership
# Changes file permissions.
chmod [who][+/-][permissions] <file>
# Makes a file executable by its owner.
chmod u+x <file>
# Changes file owner and group.
chown [user]:[group] <file>
Searching and finding
# Finds files and directories.
find [directory] -name <search_pattern>
# Searches for a pattern in files.
grep <search_pattern> <file>
Archiving and compression
# Compresses files into a tar.gz archive.
tar -czvf <name.tar.gz> [files]
# Extracts a compressed tar archive.
tar -xvf <name.tar.[gz|bz|xz]> [destination]
Text editing and processing
# Opens a file in the Nano text editor.
nano [file]
# Displays the contents of a file.
cat <file>
# Displays the paginated content of a file.
less <file>
# Shows the first few lines of a file.
head <file>
# Shows the last few lines of a file.
tail <file>
# Prints every line in a file.
awk '{print}' [file]
Packages
Package management (APT)
# Installs a package.
sudo apt install <package>
# Reinstalls a broken package.
sudo apt install -f --reinstall <package>
# Searches for APT packages.
apt search <package>
# Lists available package versions.
apt-cache policy <package>
# Updates package lists.
sudo apt update
# Upgrades all upgradable packages.
sudo apt upgrade
# Removes a package.
sudo apt remove <package>
# Removes a package and all its configuration files.
sudo apt purge <package>
Package management (Snap)
# Searches for Snap packages.
snap find <package>
# Installs a Snap package.
sudo snap install <snap_name>
# Removes a Snap package.
sudo snap remove <snap_name>
# Updates all installed Snap packages.
sudo snap refresh
# Lists all installed Snap packages.
snap list
# Displays information about a Snap package.
snap info <snap_name>
Users & Groups
User management
# Shows which users are logged in.
w
# Creates a new user.
sudo adduser <username>
# Deletes a user.
sudo deluser <username>
# Sets or changes the password for a user.
sudo passwd <username>
# Switches user.
su <username>
# Locks a user account.
sudo passwd -l <username>
# Unlocks a user password.
sudo passwd -u <username>
# Sets user password expiration date.
sudo chage <username>
Group management
# Displays user and group IDs.
id [username]
# Shows the groups a user belongs to.
groups [username]
# Creates a new group.
sudo addgroup <groupname>
# Deletes a group.
sudo delgroup <groupname>
Networking
Networking Commands
# Displays network interfaces and IP addresses.
ip addr show
# Shows network statistics.
ip -s link
# Shows listening sockets.
ss -l
# Pings a host and outputs results.
ping <host>
Netplan Configuration
# Displays the current Netplan configuration.
cat /etc/netplan/*.yaml
# Tests a new configuration for a set period of time.
sudo netplan try
# Applies the current Netplan configuration.
sudo netplan apply
Firewall Management
# Displays the status of the firewall.
sudo ufw status
# Enables the firewall.
sudo ufw enable
# Disables the firewall.
sudo ufw disable
# Allows traffic on a specific port or service.
sudo ufw allow <port/service>
# Denies traffic on a specific port or service.
sudo ufw deny <port/service>
# Deletes an existing rule.
sudo ufw delete allow/deny <port/service>
SSH and Remote Access
# Connects to a remote host via SSH.
ssh <user@host>
# Securely copies files between hosts.
scp <source> <user@host>:<destination>
LXD
LXD is a modern, secure, and powerful tool that provides a unified experience for
running and managing containers or virtual machines. Visit LXD Official Site for more information.
Initialization
# Initializes LXD before first use.
lxd init
Creating Instances
# Creates a LXC system container (without starting it).
lxc init ubuntu:22.04 <container_name>
# Creates and starts a LXC system container.
lxc launch ubuntu:24.04 <container_name>
# Creates and starts a virtual machine.
lxc launch ubuntu:22.04 <vm_name> --vm
Managing Instances
# Lists instances.
lxc list
# Shows status information about an instance.
lxc info <instance>
# Starts an instance.
lxc start <instance>
# Stops an instance.
lxc stop <instance> [--force]
# Deletes an instance.
lxc delete <instance> [--force|--interactive]
Accessing Instances
# Runs a command inside an instance.
lxc exec <instance> -- <command>
# Gets shell access to an instance (if bash is installed).
lxc exec <instance> -- bash
# Gets console access to an instance.
lxc console <instance> [flags]
# Pulls a file from an instance.
lxc file pull <instance>/<instance_filepath> <local_filepath>
# Pushes a file to an instance.
lxc file push <local_filepath> <instance>/<instance_filepath>
Using Projects
# Creates a project.
lxc project create <project> [--config <option>]
# Configures a project.
lxc project set <project> <option>
# Switches to a project.
lxc project switch <project>
Ubuntu Pro
Ubuntu Pro delivers 10 years of expanded security coverage on top of Ubuntu’s Long Term
Support (LTS) commitment in addition to management and compliance tooling. Visit Ubuntu Pro to register for free on up to five machines.
Activating Ubuntu Pro
# Attaches your machine to Ubuntu Pro using a specific token.
sudo pro attach <token>
Managing Services
# Displays the status of all Ubuntu Pro services.
sudo pro status
# Enables a specific Ubuntu Pro service, like ESM, FIPS, or Livepatch.
sudo pro enable <service>
# Disables a specific Ubuntu Pro service.
sudo pro disable <service>
Extended Security Maintenance (ESM)
# Activates Extended Security Maintenance for infrastructure packages.
sudo pro enable esm-infra
# Activates ESM for applications, extending security coverage.
sudo pro enable esm-apps
Livepatch Service
# Enables the Livepatch service, which applies critical kernel patches without rebooting.
sudo pro enable livepatch
FIPS Mode
# Enables FIPS (Federal Information Processing Standards) mode, enforcing strict cryptographic standards.
sudo pro enable fips
Updating Configuration
# Refreshes the Ubuntu Pro state to ensure the latest configuration and services are in place.
sudo pro refresh
Detaching Ubuntu Pro
# Detaches the machine from Ubuntu Pro, disabling all services.
sudo pro detach
This is a complete and structured Ubuntu CLI cheat sheet.
Top comments (0)