LinuxShellSite
CategoryCommandDescriptionPlatform
Operating System Versionlsb_release -aDisplays detailed information about the Linux distribution.Ubuntu/Debian
 cat /etc/os-releaseOutputs information about the installed operating system.All distributions
 cat /etc/issueDisplays a brief information about the distribution.All distributions
 cat /etc/redhat-releaseSpecific to Red Hat-based systems, displays the version.RHEL/CentOS
Kernel Versionuname -aDisplays all the information about the kernel.All distributions
 uname -rDisplays the kernel release version.All distributions
Hardware InformationlscpuDisplays CPU architecture information.All distributions
 LSHWLists detailed hardware information (may need to be installed).All distributions
 LSPCIDisplays information about PCI devices.All distributions
 LSUSBDisplays information about USB devices.All distributions
 dmidecodeDisplays hardware information from the BIOS/UEFI (requires root privileges).All distributions
Storage Informationfree -hDisplays the current memory consumption.All distributions
 vmstatDisplays information about system processes, memory, paging, block I/O, and CPU activity.All distributions
 cat /proc/meminfoDisplays detailed information about the memory.All distributions
Disks and partitionsdf -hDisplays the disk space of the file systems.All distributions
 du -sh /pathDisplays the size of a directory or file.All distributions
 LSBLKLists block devices such as hard drives and partitions.All distributions
 fdisk -lLists partition tables and disk information (requires root privileges).All distributions
 blkidDisplays UUIDs and types of file systems.All distributions
Network informationIP Addr ShowDisplays network interfaces and IP addresses.All distributions
 ifconfigOlder command to display network interfaces (may need to install net-tools).All distributions
 netstat -tulnLists all open ports (may need to install net-tools).All distributions
 SS -TulnModern replacement for netstat, shows open ports and connections.All distributions
 hostname -iDisplays the IP addresses of the host system.All distributions
Process InformationtopReal-time view of running processes and system utilization.All distributions
 htopImproved version of top with a user-friendly interface (must be installed).All distributions
 ps auxLists all running processes with details.All distributions
 pstreeDisplays processes in a tree-like structure.All distributions
Users and GroupswhoDisplays which users are currently logged in.All distributions
 wDisplays logged-in users and their activities.All distributions
 idDisplays user and group IDs of the current user.All distributions
 LoadDisplays users’ login history.All distributions
System logsDMESGDisplays kernel and system messages.All distributions
 journalctlDisplays logs of the system (systemd-based systems).All distributions
 tail -f /var/log/syslogReal-time view of system logs (Ubuntu/Debian).Ubuntu/Debian
 tail -f /var/log/messagesReal-time view of system logs (RHEL/CentOS).RHEL/CentOS
Package managementdpkg -lLists installed packages (Debian-based).Ubuntu/Debian
 rpm -qaLists installed RPM packages.RHEL/CentOS
 apt list –installedDisplays a list of installed packages.Ubuntu/Debian
 yum list installed or dnf list installedDisplays installed packages (YUM or DNF depending on the version).RHEL/CentOS
System Servicessystemctl list-units –type=serviceLists all active services (systemd).All distributions
 service –status-allLists the status of all services (SysVinit systems).All distributions
Environment VariablesenvDisplays all environment variables.All distributions
 PrintenvOutputs environment variables (can be used with variables, e.g. printenv PATH).All distributions
Time synchronizationtimedatectlDisplays date, time, and time zone settings.All distributions
 ntpq -pDisplays the status of the NTP service (if installed).All distributions
Other Useful CommandsuptimeShows how long the system has been running and the average system load.All distributions
 uname -mDisplays the architecture of the system (e.g. x86_64).All distributions
 cat /proc/cpuinfoDetailed information about the CPU.All distributions
 cat /proc/versionDisplays kernel version and information.All distributions
Kernel ModuleslsmodLists loaded kernel modules.All distributions
 ModInfo Module NameDisplays information about a specific kernel module.All distributions
Software and Serviceschkconfig –listLists startup services (SysVinit, RHEL/CentOS).RHEL/CentOS
 update-rc.d -n -f service removeDisplays startup services (SysVinit, Ubuntu/Debian).Ubuntu/Debian
Special toolsinxi -FDisplays extensive system information (must be installed).All distributions
 NeofetchDisplays system information in a clear format (requires installation).All distributions
 screenfetchSimilar to neofetch, displays system information with logo (must be installed).All distributions

Notes on the commands

  • Installation of additional tools:
    • Ubuntu/Debian:
      • sudo apt update
      • sudo apt install htop lshw inxi neofetch
    • RHEL/CentOS:
      • sudo yum install epel-release (for additional repositories)
      • sudo yum install htop lshw inxi neofetch
  • Root privileges: Some commands require elevated privileges. Add sudo before the command to run it with administrator privileges.
  • Deprecated commands: Commands like ifconfig and netstat are deprecated. Use ip and ss instead.

Examples

  • To view CPU information:
    Lscpu
  • View all network interfaces and their IP addresses:
    IP Addr Show
  • Monitor memory usage in real-time:
    watch -n 1 free -h
  • To determine the size of directories:
    du -sh /var/log
  • List of the 10 processes with the highest memory consumption:
    ps aux –sort=-%mem | head -n 11

Tips

  • Using man pages: Use man command to go to the manual page of a command and get detailed information.
  • Autocomplete: Use the Tab key to autocomplete commands and file names.
  • Browse history: Press Ctrl + R to search the command history backwards.

Differences between distributions

  • Package Manager:
    • Ubuntu/Debian: Use apt or dpkg.
    • RHEL/CentOS: Use yum or dnf and rpm.
  • System logs:
    • Ubuntu/Debian: Main logs are located in /var/log/syslog.
    • RHEL/CentOS: Main logs are located in /var/log/messages.
  • Service management:
    • Both now use systemctl for systemd, but older systems can use service or chkconfig.

Additional Resources

  • Documentation:
    • Official documentation of the distributions provides comprehensive information.
    • Online forums and communities such as Stack Overflow, Ubuntu Forums or CentOS Forums.
  • Further tools:
    • Glances: A cross-system monitoring tool.
    • nmon: Monitoring tool for performance measurements.