Linux OS " Commands For Trouble Shooting "

 


When troubleshooting on a Linux OS, several commands can help diagnose and resolve issues. Here's a list of essential commands categorized by common troubleshooting areas:

1. System Monitoring

  • top: Displays running processes and system resource usage (CPU, memory).
  • htop: An enhanced version of top with a more user-friendly interface.
  • vmstat: Provides system performance information, such as processes, memory, paging, block I/O, traps, and CPU activity.
  • uptime: Shows how long the system has been running, the number of users, and load averages.
  • dmesg: Displays system messages and logs from the kernel ring buffer.
  • iostat: Provides CPU and I/O statistics for devices and partitions.
  • free: Displays memory usage, including total, used, and available memory.
  • sar: Collects and reports system activity information.

2. Disk Usage and File System

  • df -h: Shows disk space usage in a human-readable format.
  • du -sh *: Displays the disk usage of files and directories.
  • lsblk: Lists information about all available or the specified block devices.
  • fdisk -l: Lists the partition tables for the specified devices.
  • mount: Displays all currently mounted filesystems.
  • umount: Unmounts filesystems.
  • fsck: Checks and repairs a Linux filesystem.

3. Network Troubleshooting

  • ifconfig: Displays network interfaces and their status.
  • ip addr show: Shows IP addresses and network interfaces.
  • ping: Checks connectivity to a remote host.
  • traceroute: Traces the route packets take to a network host.
  • netstat: Displays network connections, routing tables, and interface statistics.
  • ss: A modern replacement for netstat, showing more detailed information about network connections.
  • nslookup: Queries DNS servers for domain name or IP address mapping.
  • dig: Performs DNS queries.
  • tcpdump: Captures and analyzes network packets.
  • nmap: Scans networks for open ports and services.

4. Process Management

  • ps aux: Lists all running processes.
  • kill PID: Terminates a process by its PID (Process ID).
  • pkill process_name: Kills processes by name.
  • killall process_name: Kills all instances of a process.
  • systemctl: Manages system services (start, stop, restart, enable, disable).

5. Log Management

  • tail -f /var/log/syslog: Continuously monitors the system log file.
  • tail -f /var/log/messages: Continuously monitors the messages log file.
  • journalctl: Views logs collected by the systemd journal.
  • last: Displays the last logins of users.
  • who: Shows who is currently logged into the system.

6. User and Permission Issues

  • whoami: Displays the current user’s name.
  • id: Displays user identity, including UID, GID, and groups.
  • groups username: Lists the groups a user belongs to.
  • passwd: Changes a user's password.
  • chown: Changes file ownership.
  • chmod: Changes file permissions.
  • usermod: Modifies user accounts.

7. Package Management

  • apt-get update && apt-get upgrade: Updates package lists and upgrades all packages (Debian/Ubuntu).
  • yum update: Updates all packages (CentOS/RHEL).
  • rpm -qa: Lists all installed RPM packages.
  • dpkg -l: Lists all installed DEB packages.
  • apt-cache search package_name: Searches for a package (Debian/Ubuntu).

8. Service Management

  • systemctl start service_name: Starts a service.
  • systemctl stop service_name: Stops a service.
  • systemctl restart service_name: Restarts a service.
  • systemctl status service_name: Displays the status of a service.

9. Miscellaneous

  • uname -a: Displays system information (kernel version, etc.).
  • hostname: Shows or sets the system's hostname.
  • date: Displays or sets the system date and time.
  • crontab -e: Edits the cron jobs for the current user.

These commands are the starting points for troubleshooting most issues in a Linux environment.

Post a Comment

0 Comments