Created
November 24, 2024 22:50
-
-
Save thesaadarshad/c4ceeb9d7ce4caedb789353a659b8195 to your computer and use it in GitHub Desktop.
Linux Commands - 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Linux Commands Cheat Sheet | |
| **Category** | **Command** | **Description** | **Example** | | |
|-----------------------|------------------|------------------------------------------------------|-----------------------------------------------| | |
| **Process Monitoring**| `top` | Display real-time CPU and memory usage of processes. | `top` | | |
| | `htop` | Interactive process viewer. | `htop` | | |
| **System Metrics** | `vmstat` | Report system performance (CPU, memory, I/O, etc.). | `vmstat 5 10` (Updates every 5 seconds, 10 times) | | |
| | `iostat` | Show CPU and disk I/O statistics. | `iostat -x 1` (Extended stats every second) | | |
| **Logs & Kernel** | `dmesg` | Display boot and kernel messages. | `dmesg | tail -n 20` (Last 20 messages) | | |
| | `journalctl` | Query and display system logs. | `journalctl -xe` (View recent errors) | | |
| **Disk Metrics** | `df` | Show disk usage for all filesystems. | `df -h` (Human-readable format) | | |
| | `du` | Estimate file/directory space usage. | `du -sh /var/log` (Summarized for directory) | | |
| **I/O Analysis** | `iotop` | Show real-time I/O usage by processes. | `sudo iotop` | | |
| | `lsblk` | List information about block devices. | `lsblk -f` | | |
| | `blkid` | Show block device attributes (UUID, type, etc.). | `sudo blkid` | | |
| **Networking** | `traceroute` | Display route packets take to reach a host. | `traceroute example.com` | | |
| | `ping` | Check connectivity to a host. | `ping -c 4 google.com` (Send 4 packets) | | |
| | `netstat` | Show active connections and listening ports. | `netstat -tuln` | | |
| | `ss` | Modern replacement for `netstat`. | `ss -tuln` (TCP/UDP listening ports) | | |
| | `tcpdump` | Capture network packets for analysis. | `sudo tcpdump -i eth0 port 80` (Capture HTTP traffic) | | |
| | `ip` | Manage IP addresses and routing. | `ip addr show` | | |
| **Troubleshooting** | `strace` | Trace system calls and signals. | `strace -p <pid>` | | |
| | `lsof` | List open files by processes. | `lsof -i :80` (Processes using port 80) | | |
| | `ps` | Show details of running processes. | `ps aux | grep nginx` | | |
| **File & Disk** | `mount` | Mount a filesystem. | `mount /dev/sda1 /mnt` | | |
| | `umount` | Unmount a filesystem. | `umount /mnt` | | |
| | `fsck` | Check and repair filesystem issues. | `sudo fsck /dev/sda1` | | |
| | `tune2fs` | Adjust filesystem parameters. | `sudo tune2fs -l /dev/sda1` | | |
| **Packet Sniffing** | `tcpdump` | Capture and analyze packets on a network interface. | `sudo tcpdump -i eth0 port 443` (Capture HTTPS traffic) | | |
| | `wireshark` | Graphical packet capture and analysis tool. | `wireshark` | | |
| **TCP/IP Stack** | `sysctl` | View and configure kernel parameters. | `sysctl -a | grep tcp` (View TCP settings) | | |
| | `iptables` | Configure Linux firewall rules. | `iptables -L -v -n` (List rules) | | |
| | `ping` | Send ICMP echo requests to a host. | `ping -c 4 8.8.8.8` | | |
| **System Analysis** | `sar` | Collect and report system activity metrics. | `sar -u 1 5` (CPU usage every 1 sec for 5 iterations) | | |
| | `uptime` | Show system uptime and load averages. | `uptime` | | |
| | `free` | Display memory usage. | `free -h` (Human-readable format) | | |
--- | |
### **Notes:** | |
1. Commands requiring root permissions should be prefixed with `sudo`. | |
2. Use the `man` command for detailed documentation on each command, e.g., `man top`. | |
3. For `tcpdump` and similar tools, ensure you have proper permissions to capture packets. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment