Posted on 24th May 2017

System Information OS Version (Ubuntu Version) lsb_release -a cat /etc/os-release Kernel Release Information uname -a Disk Usage df df -h Memory Usage free free -h Uptime uptime Who are logged in w System date and time date Hostname hostname Hardware Information List hardware lshw lshw -short List PCI devices lspci lspci -v List USB devices lsusb List SCSI devices cat /proc/scsi/scsi lsscsi (if lsscsi package is installed) Display device driver messages dmesg (Pipe to grep for specific info) dmesg | grep -i usb Process Management List all processes top List active processes ps -ef Kill a process with PID pid kill pid Kill with signal 9 if above doesn't work kill -9 pid List tree of processes pstree Which process is using file fuser filename Networking List network interfaces ifconfig ip addr show Show routing tables ip route show Configure an interface Edit /etc/network/interfaces and restart networking Restart Networking systemctl restart networking /etc/init.d/networking restart service networking restart List all ports netstat -a List all active listening ports netstat -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 are systemctl 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 file find / -name filename locate filename Search for a file in path /home/mydir find /home/mydir -name filename Search for all files greater than size 100MB find / -size +100M Suppress errors while using find or any command 2>/dev/null find / -size +100M 2>/dev/null Search for pattern in a file grep pattern filename Search for pattern in directory grep -r pattern dirname Package Management Install a package using apt apt install <package-name> apt-get install <package-name> Check for broken packages apt-get check Remove broken packages apt autoremove apt-get autoremove Refresh package list apt update apt-get update List upgradable packages apt list --upgradable Upgrade packages apt upgrade apt-get upgrade Uninstall a package apt remove <package-name> apt-get remove <package-name> Uninstall a package and remove config files apt purge <package-name> apt-get purge <package-name> Search for a package apt search <package-name> apt-cache search <package-name> Show package information apt show <package-name> apt-cache show <package-name> 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.