Ubuntu Cheat Sheet (Updated for systemd based versions)

Updated on 24th May 2017

System Information

OS Version (Ubuntu Version)lsb_release -a
cat /etc/os-release
Kernel Release Informationuname -a
Disk Usagedf
df -h
Memory Usagefree
free -h
Uptimeuptime
Who are logged inw
System date and timedate
Hostnamehostname

Hardware Information

List hardwarelshw
lshw -short
List PCI deviceslspci
lspci -v
List USB deviceslsusb
List SCSI devicescat /proc/scsi/scsi
lsscsi (if lsscsi package is installed)
Display device driver messagesdmesg
(Pipe to grep for specific info)dmesg | grep -i usb

Process Management

List all processes top
List active processesps -ef
Kill a process with PID pidkill pid
Kill with signal 9 if above doesn't workkill -9 pid
List tree of processespstree
Which process is using filefuser filename

Networking

List network interfacesifconfig
ip addr show
Show routing tablesip route show
Configure an interfaceEdit /etc/network/interfaces and restart networking
Restart Networkingsystemctl restart networking
/etc/init.d/networking restart
service networking restart
List all portsnetstat -a
List all active listening portsnetstat -tupl

Service Management

Start a service called myservice/etc/init.d/myservice start
service myservice start
Stop a service called myservice/etc/init.d/myservice stop
service myservice stop
Check status of a service called myservice/etc/init.d/myservice status
service myservice status
For newer versions with systemd instead of sysvinit above commands aresystemctl start myservice
systemctl stop myservice
systemctl status myservice

Logs

General System Logs/var/log/syslog
Kernel logs/var/log/kern.log
Boot logs (sysvinit based older versions)/var/log/boot.log
Boot logs (sysemd based newer versions)journalctl -b
Kernel ring buffer log/var/log/dmesg

Search

Search for a filefind / -name filename
locate filename
Search for a file in path /home/mydirfind /home/mydir -name filename
Search for all files greater than size 100MBfind / -size +100M
Suppress errors while using find or any command2>/dev/null
find / -size +100M 2>/dev/null
Search for pattern in a filegrep pattern filename
Search for pattern in directorygrep -r pattern dirname

Package Management

Install a package using aptapt install
apt-get install
Check for broken packagesapt-get check
Remove broken packagesapt autoremove
apt-get autoremove
Refresh package listapt update
apt-get update
List upgradable packagesapt list --upgradable
Upgrade packagesapt upgrade
apt-get upgrade
Uninstall a packageapt remove
apt-get remove
Uninstall a package and remove config filesapt purge
apt-get purge
Search for a packageapt search
apt-cache search
Show package informationapt show
apt-cache show
Install a package using dpkg dpkg -i packagename.deb

Note: apt is avaialable in newer versions as a more user-friendly alternative that merges several functions of apt-get and apt-cache. However this is not a proxy command and its output can change from one version to another. So use it in scripts with caution, especially if you are going to process the output of apt.

apt-get and apt-cache are lower-level backend and backward-compatible.


Post a comment

Got a question about this article? Ask our forum

Name

Your Comment

Email (We dont publish it)

Comments

soupcan | June 6, 2017 10:19 PM |

apt-get should be changed to apt.

Remy Pereira | June 7, 2017 1:19 PM |

apt is supposed to be the successor, it is also supposed to be better and pleasant for end users, however the output of apt can change from one version to another. Hence it is not recommended to write scripts that process the output of apt.