Page Content

Tutorials

Linux DevOps Commands Cheat Sheet With Practical Examples

Linux DevOps Commands Cheat Sheet

System Observability & Resources

CommandUsage ExampleDevOps Context
uptimeuptimeChecks system load averages (1, 5, 15 mins).
htophtopInteractive process viewer (replaces top).
free -mfree -hChecks RAM usage in human-readable format.
df -hdf -h /Monitors disk space on specific partitions.
du -shdu -sh /var/log/*Finds which logs are consuming the most space.
iostatiostat -xz 1Monitors disk I/O latency and saturation.
vmstatvmstat 1Monitors memory, swap, and CPU context switches.
iotopsudo iotop -oIdentifies which process is “thrashing” the disk.
dmesgdmesg | tail -20Checks kernel logs for OOM (Out of Memory) kills.
unameuname -aVerifies kernel version and architecture.

Also read about Networking in Linux: Types, Advantages, and Disadvantages

Networking & Connectivity

CommandUsage ExampleDevOps Context
ip addrip aModern way to view IP addresses (replaces ifconfig).
ssss -tulnpLists listening ports and associated PIDs.
curlcurl -I localhost:80Tests if a local web server is responding.
digdig google.comTroubleshoots DNS resolution issues.
nc (netcat)nc -zv 10.0.0.5 22Checks if a remote port is open/reachable.
tcpdumpsudo tcpdump -i eth0Captures and inspects raw network packets.
mtrmtr google.comCombined ping and traceroute for path analysis.
wgetwget --spider <URL>Checks if a file exists on a remote server.
nslookupnslookup <domain>Quick DNS record check.
nmapnmap -sP 192.168.1.0/24Scans a subnet for active devices.

Text Processing & Log Analysis

CommandUsage ExampleDevOps Context
grepgrep -r "error" /var/logSearches for patterns recursively in files.
awkawk '{print $1}' access.logExtracts specific columns (e.g., IPs) from logs.
sedsed -i 's/old/new/g' cf.envAutomates text replacement in config files.
tail -ftail -f /var/log/syslogStreams logs in real-time.
lessless +G large_file.logOpens large logs at the end for quick viewing.
wc -lls | wc -lCounts the number of files or lines.
sortsort -nrSorts data numerically in reverse.
uniq -cuniq -cCounts occurrences of unique lines.
cutcut -d',' -f2 data.csvExtracts data based on a specific delimiter.
jqcurl ... | jq '.'Formats and parses JSON (critical for APIs/Cloud).

Also read about Explain File Permissions In Linux & Ownership With Examples

File Management & Permissions

CommandUsage ExampleDevOps Context
chmodchmod 400 key.pemSecures SSH private keys.
chownsudo chown -R www-data: /var/wwwChanges ownership for web server directories.
findfind . -mtime +7Finds files older than 7 days for cleanup.
rsyncrsync -avz local/ remote:/tmpEfficiently syncs files between servers.
tartar -czvf backup.tar.gz /dataCompresses directories for backup.
lsblklsblkLists all block devices (disks/partitions).
ln -sln -s /path/a /path/bCreates symbolic links for versioning apps.
lsoflsof -i :8080Lists which process “owns” a specific port.
shredshred -u sensitive.txtSecurely wipes a file so it can’t be recovered.
statstat config.yamlDisplays detailed file metadata (creation/mod time).

Service & Process Control

CommandUsage ExampleDevOps Context
systemctlsystemctl restart dockerManages systemd services.
journalctljournalctl -u nginx -fFollows logs for a specific service.
ps auxps aux | grep pythonLists all running processes.
kill -9kill -9 <PID>Forces a “zombie” or stuck process to exit.
nohupnohup ./script.sh &Runs a script that survives terminal logout.
bg / fgfg %1Manages background and foreground jobs.
crontab -ecrontab -eSchedules recurring maintenance tasks.
nicenice -n 10 ./build.shLowers a process priority to save CPU for others.
stracestrace -p <PID>Traces system calls to debug application hangs.
screen / tmuxtmux attachMaintains persistent terminal sessions.

User & Security

CommandUsage ExampleDevOps Context
sudo !!sudo !!Re-runs the last command with root privileges.
whoamiwhoamiConfirms the current effective user.
idid jenkinsChecks UID/GID and group memberships.
usermodusermod -aG docker $USERAdds a user to the Docker group.
visudosudo visudoSafely edits the /etc/sudoers file.
historyhistory | grep sshSearches for previously executed commands.

Also read about Explain User And Group Management In Linux With Examples

Linux commands for DevOps interview questions

In a 2026 DevOps interview, the focus has shifted from simple “What is a command?” questions to scenario-based troubleshooting and internal architecture. Interviewers want to see that you understand the “why” behind the system behavior, especially in containerized and cloud-native environments.

System Observability & Troubleshooting

Q: A developer reports their application is “slow” on a Linux server.

  • Answer: I follow the USE Method (Utilization, Saturation, and Errors).
    1. uptime / top: Check load average. Is it CPU-bound or I/O-bound?
    2. free -m: Check for memory exhaustion or heavy swapping.
    3. iostat -xz 1: Check if disk latency is high (Wait %).
    4. ss -tuln & ping: Verify network connectivity and port availability.
    5. dmesg | tail: Look for OOM (Out of Memory) kills or hardware errors.

Q: You see a “No space left on device” error, but df -h it shows 50% free space. What is happening?

  • Answer: This usually points to two possibilities:
    1. Inode Exhaustion: The filesystem has run out of index nodes. Check with df -i.
    2. Deleted files still open: A large file (like a log) was deleted, but a running process still holds the file handle. The space won’t be freed until the process is restarted. Check with lsof | grep deleted.

Kernel & Architecture (Cloud-Native focus)

Q: How do Docker containers actually “isolate” processes from each other on a single Linux host?

  • Answer: They use two primary kernel features:
    • Namespaces: Provide isolation (PID, Network, Mount, User). This makes the process think it has its own private resources.
    • Cgroups (Control Groups): Provide resource limits (CPU, RAM, I/O). This prevents a process from consuming the entire host’s resources.

Q: What is the difference between a Hard Link and a Soft Link (Symlink)?

  • Answer:
    • Hard Link: Points directly to the inode of the data. Deleting the original file doesn’t break the hard link. (Cannot cross filesystems).
    • Soft Link: Points to the filename. If the original file is moved or deleted, the link breaks (“dangling link”).

Also read about What Is Linux In Cloud & DevOps? Importance, And Commands

Service Management (systemd)

Q: What is the difference between systemctl stop and systemctl kill?

  • Answer: stop sends a SIGTERM to the service, allowing it to perform a “graceful shutdown” (closing db connections, finishing tasks). kill sends a SIGKILL by default, which immediately terminates the process without cleanup.

Q: How do you check why a service failed to start two hours ago?

  • Answer: Use journalctl -u <service_name> --since "2 hours ago". If the system is rebooted, ensure persistent logging is enabled in /etc/systemd/journald.conf.

Automation & Scripting

Q: Write a one-liner to find all .log files in /var/log larger than 100MB, and delete them.

  • Answer: find /var/log -name "*.log" -type f -size +100M -delete

Q: What is the purpose of the #! (shebang) at the start of a script?

  • Answer: It tells the kernel which interpreter to use to execute the script (e.g., #!/bin/bash or #!/usr/bin/env python3). Using /usr/bin/env is generally more portable across different Linux distributions.

Security & Networking

Q: How do you check which process is listening on Port 80?

  • Answer: sudo lsof -i :80 or sudo ss -tulpn | grep :80.

Q: What are the three modes of SELinux?

  • Answer:
  • Enforcing: Policy is enabled, and access is blocked.
  • Permissive: Policy is enabled, but access is not blocked (violations are just logged).
  • Disabled: The security module is completely off.

Also read about Linux Troubleshooting Commands With Examples & Cheat Sheet

Hemavathi
Hemavathihttps://govindhtech.com/
Myself Hemavathi graduated in 2018, working as Content writer at Govindtech Solutions. Passionate at Tech News & latest technologies. Desire to improve skills in Tech writing.
Index