A useful Ubuntu command line cheat sheet for 2026 needs to be searchable, copy-ready, and honest about what changes between releases. Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS share the same core terminal workflow, but APT output, coreutils behavior, and optional tools can differ enough that older printable sheets need a few current notes.
Use the commands here as a practical Ubuntu terminal reference for package management, files, users, services, logs, networking, firewall checks, remote access, and Ubuntu-specific tools. When a command changes system state, read the surrounding note before pasting it into a production server or remote SSH session.
Ubuntu Command Line Cheat Sheet Quick Reference
Start with the commands that answer the most common Ubuntu terminal questions: where you are, which release you are running, what packages can change, which services are active, and where logs live.
| Task | Command | What It Does |
|---|---|---|
| Show current directory | pwd | Prints the shell’s current working directory. |
| List files | ls -la | Lists normal and hidden entries with permissions, owner, size, and date. |
| Change directory | cd /path/to/directory | Moves the current shell to another directory. |
| Check Ubuntu release | lsb_release -a | Shows the release number, codename, and description when the helper is installed. |
| Check release fields | grep -E '^(VERSION_ID|VERSION_CODENAME)=' /etc/os-release | Reads exact release fields from a file present on normal Ubuntu installs. |
| Refresh package metadata | sudo apt update | Downloads current package lists from enabled APT sources. |
| Upgrade packages | sudo apt upgrade | Upgrades installed packages without removing packages. |
| Check service status | systemctl status <service> | Shows whether a systemd service is loaded, active, and logging errors. |
| Read service logs | journalctl -u <service> -n 50 --no-pager | Prints the newest 50 journal entries for one unit. |
| Show IP addresses | ip -brief addr | Lists interfaces and addresses in a compact format. |
| Show listening TCP ports | ss -ltn | Lists local TCP sockets that are waiting for connections. |
| Check firewall state | sudo ufw status verbose | Shows UFW status and active rules when UFW is installed. |
| Open command help | man <command> or <command> --help | Shows detailed or short help for a command. |
Read Ubuntu Command Syntax Correctly
Cheat sheets often use placeholder values. Replace the placeholder and remove the angle brackets before running the command. For example, sudo apt install <package> becomes sudo apt install htop, not sudo apt install <htop>.
Commands with
sudocan change system files, users, services, firewall policy, or packages. On remote systems, confirm your SSH access and the command target before restarting services, enabling firewalls, removing packages, or editing network configuration.
The same command can print different output on supported Ubuntu LTS releases. The main difference for package maintenance is APT: Ubuntu 26.04 uses APT 3, while Ubuntu 24.04 and 22.04 use APT 2. The command behavior is usually the same, but transaction summaries and status wording can differ.
| Ubuntu Release | Codename | CLI Note |
|---|---|---|
| Ubuntu 26.04 LTS | resolute | Uses APT 3 and introduces rust-coreutils for many base utilities while keeping GNU implementations for some commands. Prefer explicit forms such as head -n 20 instead of shorthand like head -20. |
| Ubuntu 24.04 LTS | noble | Uses APT 2 with GNU coreutils by default, so many package examples show older APT output wording. |
| Ubuntu 22.04 LTS | jammy | Uses older APT 2, GNU coreutils, Bash, and systemd versions; avoid assuming newer Bash or command options without checking help. |
For release-specific repository work, confirm the codename first with:
lsb_release -rs
lsb_release -cs
On Ubuntu 26.04, those commands print:
26.04 resolute
For deeper release checks, use the dedicated guide to check the Ubuntu version from the terminal.
Manage Ubuntu Packages with APT and Snap
APT manages Ubuntu repository packages and third-party APT sources. Snap manages Snap packages through the Snap Store. Keep those package sources separate when you install, update, troubleshoot, or remove software.
APT Command Cheat Sheet
| Task | Command | What It Does |
|---|---|---|
| Refresh package lists | sudo apt update | Downloads current metadata from every enabled APT source. |
| Show pending upgrades | apt list --upgradable | Lists installed packages with newer candidates. |
| Upgrade installed packages | sudo apt upgrade | Applies upgrades without removing installed packages. |
| Resolve broader dependency changes | sudo apt full-upgrade | Allows package removals or new dependency choices when needed. |
| Search package descriptions | apt search <name> | Searches package names and descriptions. |
| Inspect candidate source | apt-cache policy <package> | Shows installed version, candidate version, and package source priorities. |
| Install a package | sudo apt install <package> | Installs the named package and required dependencies. |
| Upgrade one installed package | sudo apt install --only-upgrade <package> | Upgrades the package only if it is already installed. |
| Reinstall a package | sudo apt install --reinstall <package> | Reinstalls files from the package while keeping package state. |
| Fix broken dependencies | sudo apt --fix-broken install | Attempts to complete or repair an interrupted dependency transaction. |
| Remove package binaries | sudo apt remove <package> | Removes the package while leaving system configuration files. |
| Purge package configuration | sudo apt purge <package> | Removes the package and its package-owned configuration files. |
| Remove unused dependencies | sudo apt autoremove | Removes packages installed automatically that are no longer needed. |
| Clean downloaded package files | sudo apt clean | Clears downloaded package archives from APT’s cache. |
For routine maintenance, use a reviewable sequence instead of adding -y to every command:
sudo apt update
apt list --upgradable
sudo apt upgrade
APT 3 History Commands on Ubuntu 26.04
Ubuntu 26.04’s APT 3 command set adds transaction history commands. Use the read-only history commands first; undo and redo operations can remove or reinstall packages, so review the proposed transaction before confirming.
| Task | Command | What It Does |
|---|---|---|
| List APT history | apt history-list | Shows recent APT transactions with IDs, dates, actions, and changed package counts. |
| Inspect one transaction | apt history-info <id> | Shows details for a selected transaction ID. |
| Undo a transaction | sudo apt history-undo <id> | Proposes the inverse transaction so you can review it before continuing. |
| Redo a transaction | sudo apt history-redo <id> | Repeats a previous transaction when the packages are still available. |
Use the full maintenance article when you need more detail on updating Ubuntu packages from the command line. For cleanup decisions, use the separate guide to remove packages on Ubuntu from the command line. For downloaded local packages, APT can install and remove local .deb files cleanly when you follow the Ubuntu DEB file workflow.
If APT cannot find a package that should exist, refresh metadata first and then check whether the required component is enabled. Many desktop and community packages live in Universe or Multiverse, which you can review with the guide to enable Universe and Multiverse on Ubuntu.
Snap Command Cheat Sheet
| Task | Command | What It Does |
|---|---|---|
| Search for snaps | snap find <name> | Searches the Snap Store. |
| Show snap details | snap info <snap> | Shows channels, publisher, installed state, and description. |
| Install a snap | sudo snap install <snap> | Installs the snap from its default channel. |
| List installed snaps | snap list | Lists installed Snap packages and revisions. |
| Refresh snaps | sudo snap refresh | Updates installed snaps according to Snap refresh policy. |
| Remove a snap | sudo snap remove <snap> | Removes the selected snap and may keep a recovery snapshot. |
Standard Ubuntu Desktop and Server installs normally include snap, but minimal images, containers, and custom builds can omit it. Other useful commands, including htop, tree, curl, and lxc, are optional tools rather than a safe assumption on every Ubuntu install.
Navigate and Manage Files on Ubuntu
File commands are safest when you start in the right directory and quote paths that contain spaces. Use pwd before destructive commands, and prefer exact paths over broad recursive cleanup.
| Task | Command | What It Does |
|---|---|---|
| Show current path | pwd | Prints the current directory. |
| List one entry per line | ls -1 | Prints a compact list for scanning or pipelines. |
| Long list with hidden files | ls -la | Shows permissions, owner, group, size, date, and hidden entries. |
| Change to home | cd or cd ~ | Returns to the current user’s home directory. |
| Return to previous directory | cd - | Switches back to the previous working directory. |
| Create nested directories | mkdir -p project/logs | Creates parent directories as needed. |
| Create or update a file timestamp | touch file.txt | Creates an empty file or updates an existing file’s timestamp. |
| Copy a file | cp source.txt destination.txt | Copies one file to a new path. |
| Copy a directory recursively | cp -a source-dir backup-dir | Copies a directory while preserving metadata. |
| Move or rename | mv old-name new-name | Moves or renames a file or directory. |
| Remove one file | rm file.txt | Deletes a file immediately. |
| Remove an empty directory | rmdir empty-dir | Deletes only an empty directory. |
| Find files by name | find . -type f -name '*.log' | Searches from the current directory for matching files. |
| Identify a file type | file archive.tar.gz | Reports the file type based on content and metadata. |
The cd command is a shell built-in, not a separate package. Use the detailed cd command guide for path expansion, cd -, and symbolic-link behavior. For permission-sensitive cleanup, review the chmod command examples before changing modes recursively.
Archive and Compress Files on Ubuntu
Archive commands are common in downloads, backups, log bundles, and software releases. Check the archive type with file when the extension is unclear, and extract into a directory you control before moving files into system paths.
| Task | Command | What It Does |
|---|---|---|
| Create a gzip tar archive | tar -czf backup.tar.gz folder/ | Creates a compressed tar archive from a directory. |
| List archive contents | tar -tzf backup.tar.gz | Shows what a gzip tar archive contains before extraction. |
| Extract a gzip tar archive | tar -xzf backup.tar.gz -C ./restore | Extracts the archive into a chosen directory. |
| Compress one file | gzip file.log | Creates file.log.gz and removes the original file. |
| Decompress one gzip file | gunzip file.log.gz | Restores the original uncompressed file. |
| Create a ZIP archive | zip -r project.zip project/ | Compresses a directory into a ZIP file when zip is installed. |
| Extract a ZIP archive | unzip project.zip -d ./project | Extracts a ZIP archive into a target directory when unzip is installed. |
On minimal Ubuntu systems, confirm zip, unzip, or 7z exists with command -v before using those rows. For deeper examples, use the guide to open GZ and TGZ files in Linux or the workflow to unzip archives into a directory. If a workflow needs the 7z command, install it first with the 7-Zip on Ubuntu guide.
Read, Search, and Process Text
Ubuntu terminal work often starts with reading logs, filtering configuration, or counting matching lines. Prefer explicit options such as head -n 20 and tail -n 50 because they read clearly and avoid implementation-specific shorthand.
| Task | Command | What It Does |
|---|---|---|
| Print a whole file | cat file.txt | Writes file contents to the terminal. |
| Page through a file | less file.txt | Opens a scrollable viewer; press q to quit. |
| Print first lines | head -n 20 file.txt | Shows the first 20 lines. |
| Print newest log lines | tail -n 50 /var/log/syslog | Shows the last 50 lines. |
| Follow a growing log | tail -f /var/log/syslog | Prints new lines as they are appended. |
| Search for text | grep -n 'error' app.log | Prints matching lines with line numbers. |
| Search recursively | grep -R 'server_name' /etc/nginx | Searches files under a directory. |
| Print selected fields | awk '{print $1}' file.txt | Prints the first whitespace-separated field from each line. |
| Preview line ranges | sed -n '10,20p' file.txt | Prints only lines 10 through 20. |
| Count lines | wc -l file.txt | Counts newline-delimited lines. |
| Sort and de-duplicate | sort file.txt | uniq | Sorts lines and removes adjacent duplicates. |
| Write output as root | printf '%s\n' 'value' | sudo tee /etc/example.conf | Writes piped text to a root-owned file. |
Use the grep command guide for pattern matching, the tail command guide for live log-following examples, and the sed command examples for repeatable stream edits. For URL downloads and HTTP checks, use wget examples when wget is available, or use the curl command guide when curl is installed and the workflow needs curl-specific options.
Change Permissions, Users, and Groups
User and permission commands can affect login access, service files, and private data. Check the target account, group, and path before applying recursive ownership or mode changes.
| Task | Command | What It Does |
|---|---|---|
| Show current identity | id | Prints user ID, group ID, and supplementary groups. |
| Show another user’s groups | groups <username> | Lists the groups for a named account. |
| Show logged-in users | w or who | Shows current login sessions. |
| Validate sudo access | sudo -v | Refreshes sudo credentials or fails if the account lacks sudo access. |
| Create an interactive user | sudo adduser <username> | Creates a user through Ubuntu’s friendly account helper. |
| Add user to a group | sudo usermod -aG <group> <username> | Adds a user to a supplementary group without replacing existing groups. |
| Delete a user | sudo deluser <username> | Removes the account but does not automatically delete every related file. |
| Set a password | sudo passwd <username> | Sets or changes a user’s password. |
| Lock a password | sudo passwd -l <username> | Locks password login for the account. |
| Change file mode | chmod 640 file.conf | Sets owner, group, and other permissions with numeric mode. |
| Add executable bit | chmod u+x script.sh | Makes a script executable by its owner. |
| Change owner and group | sudo chown user:group file | Assigns ownership to a user and group. |
Ubuntu keeps routine administration tied to sudo. If a new administrator cannot run privileged commands, use the full workflow to add a new user to sudoers on Ubuntu instead of editing sudoers blindly.
Inspect Processes, Services, and Logs
Ubuntu uses systemd for system services. Start with read-only status and log commands before restarting daemons, killing processes, or enabling services at boot.
| Task | Command | What It Does |
|---|---|---|
| Show uptime and load | uptime | Prints system uptime and load averages. |
| Interactive process view | top | Shows live CPU, memory, and process activity. |
| List process table | ps aux | Prints a broad process list. |
| Find process IDs | pgrep -a <name> | Finds processes by name and shows command lines. |
| Terminate by process ID | kill <pid> | Sends the default terminate signal to one process. |
| Run command in background | <command> & | Starts a command while returning control to the shell. |
| List shell jobs | jobs | Shows jobs started by the current shell. |
| Bring job to foreground | fg %1 | Returns job 1 to the foreground. |
| Check service state | systemctl is-active <service> | Prints whether a unit is active. |
| Show service details | systemctl status <service> | Shows load state, active state, recent logs, and unit metadata. |
| Restart a service | sudo systemctl restart <service> | Stops and starts a service. |
| Reload configuration | sudo systemctl reload <service> | Reloads configuration when the unit supports reload. |
| Enable service at boot | sudo systemctl enable --now <service> | Starts the service now and enables it for future boots. |
| Read unit logs | journalctl -u <service> -n 50 --no-pager | Shows recent journal entries for a service. |
| Follow live logs | journalctl -f | Prints new journal entries as they arrive. |
| List systemd timers | systemctl list-timers --all | Shows scheduled systemd timers. |
| Edit user cron jobs | crontab -e | Opens the current user’s crontab in an editor. |
| List user cron jobs | crontab -l | Prints the current user’s scheduled cron entries. |
Use systemctl status for diagnosis, but use narrower checks such as systemctl is-active in scripts. A service can have a different unit name than the package name, so verify the exact unit with systemctl list-unit-files | grep '<name>' when a status command returns Unit not found.
Check Networking, Firewall, and Remote Access
Networking commands should separate local interface state, DNS resolution, listening sockets, firewall rules, and remote connectivity. Do not open firewall ports until the service is actually listening and the intended access path is clear.
| Task | Command | What It Does |
|---|---|---|
| Show interface addresses | ip -brief addr | Lists interfaces and assigned addresses. |
| Show routes | ip route | Prints the kernel routing table. |
| Show listening TCP sockets | ss -ltn | Shows TCP ports waiting for connections. |
| Show process names for sockets | sudo ss -ltnp | Adds process details for listening TCP sockets. |
| Test IP reachability | ping -c 4 1.1.1.1 | Sends four ICMP requests to a public IP address. |
| Test DNS and reachability | ping -c 4 ubuntu.com | Checks whether a hostname resolves and responds to ICMP. |
| Check DNS resolver state | resolvectl status | Shows resolver servers and per-link DNS state. |
| Download a URL | wget <url> | Downloads the URL you provide over HTTP or HTTPS. |
| Check UFW status | sudo ufw status verbose | Shows whether UFW is active and which rules exist. |
| Allow the OpenSSH UFW profile | sudo ufw allow OpenSSH | Adds the packaged OpenSSH application rule when the profile exists. |
| Allow a TCP port | sudo ufw allow 8080/tcp | Allows inbound TCP traffic to port 8080. |
| Connect over SSH | ssh user@example.com | Starts a remote shell over SSH. |
| Copy a file over SSH | scp file.txt user@example.com:/tmp/ | Copies one local file to a remote host. |
| Review Netplan config | sudo cat /etc/netplan/*.yaml | Prints matching Netplan YAML files, including root-readable configurations. |
| Test Netplan changes | sudo netplan try | Applies a network change temporarily so it can roll back if not confirmed. |
| Apply Netplan changes | sudo netplan apply | Applies the current Netplan configuration. |
Use the focused Ubuntu workflows when you need to enable or disable the firewall on Ubuntu or enable SSH on Ubuntu. For client flags, one-off remote commands, and tunnels, use the ssh command guide.
Use Ubuntu-Specific CLI Tools
Ubuntu also ships or documents tools that are less universal than basic shell commands. Treat these as context-specific commands: they only apply when the feature is installed, configured, or part of your support plan.
| Area | Command | Use It When |
|---|---|---|
| Ubuntu Pro | pro status | You need to see whether Ubuntu Pro services are attached or enabled. |
| Ubuntu Pro | sudo pro attach <token> | You are attaching a system to a valid Ubuntu Pro subscription token. |
| Ubuntu Pro | sudo pro enable livepatch | You want to enable Livepatch on a supported attached system. |
| LXD | lxc list | LXD is installed and initialized, and you need to list instances. |
| LXD | lxc launch ubuntu:26.04 <name> | You want to create and start an Ubuntu 26.04 LTS container from an image alias. |
| LXD | lxc exec <instance> -- bash | You need a shell inside a running LXD instance. |
| Netplan | sudo netplan get | You want Netplan to print the merged network configuration, including root-readable files. |
| Netplan | sudo netplan try | You are testing a network change and need an automatic rollback window. |
The pro command is part of normal Ubuntu Pro tooling on current Ubuntu LTS systems. The lxc command appears only after LXD is installed, so do not copy LXD commands from a cheat sheet onto a base server and expect them to exist. Canonical maintains separate resources for Ubuntu Pro and LXD.
Troubleshoot Common Ubuntu CLI Errors
Most command-line problems become easier once you identify whether the failure is a missing command, missing package source, permission issue, locked package manager, wrong service name, or wrong path.
| Symptom | First Check | Likely Next Step |
|---|---|---|
command not found | command -v <command> | Install the package that provides the command or use a built-in alternative. |
E: Unable to locate package | sudo apt update and apt-cache policy <package> | Check spelling, enabled APT sources, and Universe or Multiverse availability. |
Permission denied | ls -ld <path> and id | Fix ownership or permissions only after confirming the correct target path. |
| APT or dpkg lock message | pgrep -af '[a]pt|[d]pkg' | Wait for the active package task or inspect apt-daily services; do not delete lock files as a first response. |
Unit not found | systemctl list-unit-files | grep '<name>' | Verify the installed package and exact service unit name. |
No such file or directory | pwd and ls -la | Confirm the current directory, quote paths with spaces, and check whether the file exists. |
| Firewall rule did not work | sudo ufw status numbered and sudo ss -ltnp | Confirm the service is listening on the expected port before changing firewall policy. |
| DNS lookup fails | resolvectl status and ping -c 4 1.1.1.1 | Separate DNS resolver problems from general network reachability. |
For package inventory checks after troubleshooting, use the guide to list installed packages on Ubuntu. Package ownership matters when a command exists in more than one location or a previous manual install shadows the APT-managed version.
Official Ubuntu CLI Resources
Canonical maintains an Ubuntu Server command-line cheat sheet in the official documentation and a downloadable Ubuntu CLI cheat sheet PDF. Those resources are useful for quick lookup; release notes, optional-command caveats, and full workflow links still matter when a command depends on release, package source, or system state.
For release status and support context, use Ubuntu’s official release cycle page. For 26.04-specific terminal changes such as APT 3, rust-coreutils, Netplan 1.2, and systemd 259, review the Ubuntu 26.04 LTS summary for LTS users.
Conclusion
Ubuntu terminal work is easier when quick lookups start with the right command family and a clear risk boundary. Use the linked workflows when a command changes packages, users, services, firewall rules, network access, or release-specific configuration, then verify the result before moving to the next command.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>