LinuxShellSite
CommandDescriptionPlatformExample
journalctlDisplays log entries from systemd . Allows filtering by services, priorities, time periods, etc.Systemd-based systems (Ubuntu from 15.04, RHEL/CentOS 7+)journalctl -u ssh.service
DMESGDisplays kernel ring buffer messages, useful for hardware and driver issues.All‘dmesg
tailDisplays the last lines of a file, often used to monitor ongoing logs.Alltail -f /var/log/syslog
grepSearches files or outputs for patterns, useful for filtering log entries.Allgrep error /var/log/syslog
lessInteractive pager for displaying text files, allows comfortable navigation in logs.Allless /var/log/syslog
catOutputs the contents of files on the console.Allcat /var/log/syslog
LoggerWrites messages to the system log, useful for testing.Alllogger “test message”
rsyslogA daemon for processing log messages, configurable via /etc/rsyslog.conf.All
/var/log/syslogContains general system messages and errors (main log file).Ubuntu/Debian
/var/log/messagesContains general system and kernel messages.RHEL/CentOS
/var/log/auth.logLogs authentication attempts, useful for security checks.Ubuntu/Debian
/var/log/secureContains security and authentication messages.RHEL/CentOS
LogrotateUtility for rotating, compressing, and deleting old log files, configurable via /etc/logrotate.conf.All
straceTracks system calls of a process, useful for troubleshooting programs.Allstrace -p
lsofLists open files, can be used to see which processes are using log files.Alllsof /var/log/syslog
netstat/ssDisplays network connections, useful for troubleshooting network services.Allnetstat tulips or ss tulips
psDisplays running processes, can be used to identify hanging processes.Allps aux
top / htopReal-time system monitoring, displays CPU, memory consumption and running processes.Alltop or htop
systemctlControls systemd services, can be used to check service status.Systemd-based systemssystemctl status sshd
ServiceControls system services in SysVinit systems.Legacy SystemsService SSH Status
chkconfigManaging system services at boot (SysVinit).RHEL/CentOS (older versions)chkconfig –list
update-rc.dManaging startup scripts (SysVinit).Ubuntu/Debian (older versions)update-rc.d ssh enable
uptimeDisplays how long the system has been running, as well as the average system load.Alluptime
freeDisplays memory and swap usage, helpful for memory issues.Allfree -h
vmstatDisplays system performance, including memory, swap, CPU usage.AllVMSTAT 5
sarSystem Activity Report, provides historical performance data (part of the sysstat package).Allsar -u 1 3
IOSTATDisplays CPU and I/O statistics for devices and partitions (sysstat package required).AllIOSTAT -XZ 5
tcpdumpIntercept and display network packets, helpful for network troubleshooting.Alltcpdump -i eth0 port 80
pingChecks the reachability of hosts, basic network diagnostics.Allping example.com
TracerouteShows the path of the packets to the target host, useful in case of network problems.AllTraceroute example.com
mtrCombination of ping and traceroute, provides continuous monitoring.Allmtr example.com
hostnamectlDisplays system information, including kernel and architecture (systemd).Systemd-based systemshostnamectl
whoDisplays which users are logged in, useful for monitoring.Allwho
LoadShows a list of recent logins, can be used for security checks.AllLoad
sudoExecutes commands with administrator privileges, important for commands that require root privileges.Allsudo tail /var/log/auth.log

Notes on platform differences

  • Systemd vs. SysVinit:
    • Systemd is the default init system in modern distributions such as Ubuntu (from 15.04), RHEL/CentOS 7 and later.
    • Older versions use SysVinit, which requires the use of commands such as service and chkconfig.
  • Log files:
    • Ubuntu/Debian:
      • General system messages: /var/log/syslog
      • Authentication protocols: /var/log/auth.log
    • RHEL/CentOS:
      • General system messages: /var/log/messages
      • Authentication protocols: /var/log/secure

Additional Tools

ToolDescriptionExample
gdBDebugger for programs, useful for crash analysis.gdb /path/to/program
valgrindTool to uncover memory errors and memory leaks.Valgrind ./Program
ltraceTracks calls to library functions, useful for debugging programs.LTRACE ./Program
IPModern network management tool, replaces older tools such as ifconfig.IP Addr Show
ethtoolDisplays and changes settings for network interfaces, helpful in case of network problems.ethtool eth0
nslookup / digPerform DNS queries, helpful for troubleshooting name resolution.dig example.com
fdisk / lsblkDisplays disks and partitions, useful in case of storage problems.LSBLK
LSHWLists hardware components of the system.lshw -short

Example of troubleshooting

Problem: A service does not start correctly.

Troubleshooting steps:

  1. Check service status:
    • Systemd:
      • systemctl status
    • SysVinit:
      • Service Status
  1. To view logs of the service:
    • journalctl -u (Systemd)
    • Checking the relevant log files:
      • Ubuntu/Debian: /var/log/syslog, /var/log/auth.log
      • RHEL/CentOS: /var/log/messages, /var/log/secure
  1. Filtering error messages:
    • grep -i error /var/log/syslog (Ubuntu/Debian)
    • grep -i error /var/log/messages (RHEL/CentOS)
  1. Check configuration files:
    • Perform a syntax check (if available):
      • For example, for Nginx: nginx -t
      • For Apache: apachectl configtest
  1. Check ports and network:
    • To check if the port is already in use:
      • sudo lsof -i :
    • To view network connections:
      • netstat tulips or ss tulips
  1. Review resources:
    • Check CPU and memory usage:
      • top or htop
    • Check disk space:
      • df -h
  1. To rule out hardware problems:
    • Checking kernel messages:
      • dmesg | less