Linux Commands Cheat Sheet for DevOps Engineers
Linux Commands Cheat Sheet for DevOps Engineers
1.System Information
lsb_release -a :Displays Ubuntu version, codename, and release details.
uname -a :Shows kernel version, hostname, architecture, and more.
cat /etc/os-release :Provides OS name, version, and other metadata.
free -h :Shows memory (RAM) usage in a human-readable format.
df -h :Displays disk space usage.
hostnamectl :Displays hostname, OS, and virtualization details.
uptime :Shows how long the system has been running and load averages.
2.Folder Structure
/boot :Stores files needed for booting the system (not relevant in containers).
/usr :Contains most user-installed applications and libraries.
/var :Stores logs, caches, and temporary files that change frequently.
/etc :Stores system configuration files.
Mount Points
/mnt :Temporary mount point for external filesystems.
/media :Mount point for removable media (USB, CDs).
/data :Likely your mounted volume from Windows (C:/ubuntu-data).
Modifying Users
usermod -l new_username old_username :Change the username
usermod -d /new/home/directory -m username :Change the home directory
usermod -s /bin/zsh username :Change the default shell
Deleting Users
userdel username :To remove a user but keep their home directory
userdel -r username :To remove a user and their home directory
Special Permissions
chmod u+s filename : Allows users to run a file with the file owner's permissions
Using pgrep
pgrep processname :Find a process by name and return its PID
Using pidof
pidof processname :Find the PID of a running program
Managing Processes
kill PID :To terminate a process by PID
pkill processname :To terminate using process name
kill -9 PID :Force kill a process
pkill -9 processname :Kill all instances of a process
Daemon Processes
systemctl list-units --type=service :Daemon processes run in the background without user
intervention. List all system daemons
systemctl start service-name :Stop a daemon
systemctl enable service-name :Enable a service at startup
7.System Monitoring
CPU and Memory Monitoring
top – Real-time system monitoring
htop – Interactive process viewer (requires installation)
vmstat – Report system performance statistics
free -m – Show memory usage
Disk Monitoring
df -h – Check disk space usage
du -sh /path – Show disk usage of a specific directory
iostat – Display CPU and disk I/O statistics
Network Monitoring
ifconfig – Show network interfaces (deprecated, use ip a)
ip a – Show network interface details
netstat -tulnp – Show active connections and listening ports
ss -tulnp – Alternative to netstat for socket statistics
ping hostname – Test network connectivity
traceroute hostname – Show network path to a host
nslookup domain – Get DNS resolution details
Log Monitoring
tail -f /var/log/syslog – Live monitoring of system logs
journalctl -f – Live system logs for systemd-based distros
dmesg | tail – View kernel logs
Network Monitoring
Checking Network Interfaces
ip a # Show IP addresses and interfaces
Viewing Open Ports and Connections
netstat -tulnp # Show listening ports
ss -tulnp # Alternative to netstat
Testing Connectivity
ping google.com # Test internet connection
traceroute google.com # Trace the path to Google
Checking DNS Resolution
nslookup example.com
Log Monitoring
Live Monitoring of System Logs
tail -f /var/log/syslog # Follow logs in real-time
journalctl -f # Systemd logs
Checking Kernel Logs
dmesg | tail