Refresh package index before installing anything
apt updateFrequently used Ubuntu commands for APT packages, systemd services, Netplan networking, disk mounts and UFW firewall.
Refresh package index before installing anything
apt updateUpgrade installed packages
apt upgrade -yInstall a package without prompting
apt install -y nginxRemove a package together with its config files
apt remove --purge nginxRemove automatically installed unused dependencies
apt autoremove --purgeSearch packages in configured repositories
apt search nginxCheck whether a package is installed
apt list --installed | grep nginxInstall a local deb package
dpkg -i ./package.debList installed deb packages and versions
dpkg -l | grep nginxStart a service
systemctl start nginxRestart a service
systemctl restart nginxEnable at boot and start immediately
systemctl enable --now nginxReload unit files after editing them
systemctl daemon-reloadList currently running services
systemctl list-units --type=service --state=runningShow today's logs for a service
journalctl -u nginx --since todayList Netplan configuration files
ls /etc/netplan/Test a config and auto-rollback on timeout to avoid losing access
sudo netplan tryApply the network configuration
sudo netplan applyShow the routing table and default gateway
ip routeShow DNS resolver status
resolvectl statusList locally listening ports
ss -tunlpShow block devices, filesystems and mount points
lsblk -fList disk partition information
sudo fdisk -lMount a partition temporarily
sudo mount /dev/sdb1 /dataShow partition UUID for use in fstab
sudo blkid /dev/sdb1Show disk usage and filesystem types
df -hTRemount everything in fstab to validate the configuration
sudo mount -aShow Ubuntu version details
lsb_release -aSet the system hostname
hostnamectl set-hostname web01Set the timezone to Asia/Shanghai
timedatectl set-timezone Asia/ShanghaiCheck time synchronization status
timedatectl statusShow the running kernel version
uname -rShow firewall status and existing rules
sudo ufw status verboseAllow SSH before enabling the firewall
sudo ufw allow 22/tcpAllow a port from a specific subnet
sudo ufw allow from 10.0.0.0/8 to any port 3306Enable the firewall
sudo ufw enableDelete an existing allow rule
sudo ufw delete allow 80/tcpThis website uses cookies to ensure you get the best experience on our website. Privacy Policy.