Direct answers to common Linux DevOps interview questions with practical examples, command explanations, and troubleshooting solutions. This guide provides ready-to-use answers for your interview preparation.
1. Essential Linux Commands with Examples
Practical command usage with real examples that you can use directly in interviews and daily work.
Q: How do you find which process is using a specific port?
NetworkingDirect Answer:
Use ss (preferred) or netstat command:
Example Output:
Practical Scenarios:
- Port conflict troubleshooting:
# When you get "Address already in use" error sudo ss -tulpn | grep :8080 # If something is using it, either kill it or change your port
- Security audit:
# Find all open ports on system sudo ss -tulpn # Check for unexpected services listening on public interfaces
- Service verification:
# Verify your service is listening on correct port sudo ss -tulpn | grep -E "(nginx|apache|your-service)"
Why This Answer Works:
- Shows multiple methods: Demonstrates knowledge of different tools
- Includes modern practices:
ssis preferred overnetstatin modern Linux - Practical examples: Provides real commands that can be used immediately
- Explains options: Breaks down what each flag does
- Real-world scenarios: Shows when and why you'd use these commands
Q: How to check disk space usage and find large files?
FilesystemDirect Answer:
For disk space:
For finding large files:
Practical Scenarios:
Common Issues & Solutions:
| Issue | Command to Diagnose | Solution |
|---|---|---|
| Disk full | df -h |
Clean /tmp, /var/log, or use largest file finders |
| Inode exhaustion | df -i |
Remove many small files, increase inode count at format |
| Docker disk usage | docker system df |
docker system prune |
| Log files growing | find /var/log -size +100M |
Rotate logs, compress old logs, adjust log level |
Pro Tips:
- Use
2>/dev/nullto suppress permission denied errors - Combine commands with pipes for efficient analysis
- Monitor regularly with scripts to prevent disk issues
- Consider using LVM for easier disk space management
- Set up log rotation to prevent log file issues
Q: How to view and search through logs effectively?
CommandsDirect Answer:
Essential log viewing commands:
Advanced log analysis:
Log File Locations:
| Log Type | Location | Purpose |
|---|---|---|
| System Logs | /var/log/syslog/var/log/messages |
General system messages |
| Authentication | /var/log/auth.log/var/log/secure |
Login attempts, sudo usage |
| Kernel | /var/log/kern.logdmesg |
Kernel messages, hardware errors |
| Web Server | /var/log/nginx/*/var/log/apache2/* |
Web server access/error logs |
| Database | /var/log/mysql/*/var/log/postgresql/* |
Database operations and errors |
| Application | /var/log/app/* |
Custom application logs |
Practical Troubleshooting Examples:
Production Tips:
- Use log rotation to prevent disk filling:
# Check logrotate configuration ls /etc/logrotate.d/ # Common configs: nginx, mysql, syslog
- Centralize logs with ELK stack or Loki for distributed systems
- Set up alerts for critical errors in logs
- Use structured logging (JSON format) for easier parsing
- Implement log retention policies based on compliance needs
2. Process & Performance Management
Managing processes, monitoring performance, and troubleshooting system resource issues.
Q: How to monitor CPU and memory usage in real-time?
MonitoringDirect Answer:
Real-time monitoring tools:
Monitoring specific processes:
Performance metrics interpretation:
Common performance issues:
| Symptom | Diagnostic Command | Possible Cause | Solution |
|---|---|---|---|
| High CPU usage | top, ps aux --sort=-%cpu |
Buggy code, infinite loop, high traffic | Optimize code, scale horizontally, kill runaway process |
| High memory usage | free -h, ps aux --sort=-%mem |
Memory leak, insufficient RAM, too many processes | Restart service, add RAM, optimize memory usage |
| High I/O wait | iostat -x 1, iotop |
Slow disk, heavy database queries, logging | Use SSD, optimize queries, move logs to separate disk |
| High load average | uptime, top |
Too many processes, CPU saturation | Reduce concurrency, add more CPUs, optimize code |
| Swap thrashing | vmstat 1, free -h |
Insufficient RAM | Add more RAM, reduce memory usage, adjust swappiness |
Automated monitoring script:
When to Use Which Tool:
- Quick check:
toporhtop - Detailed analysis:
vmstat,mpstat,iostat - Historical data:
sar(requires sysstat configured) - Interactive monitoring:
glancesornmon - Process-specific:
/proc/[pid]/files - Production monitoring: Prometheus + Grafana
Q: How to kill a process that's not responding?
ProcessDirect Answer:
Step-by-step process termination:
Advanced scenarios:
Signal reference:
| Signal | Number | Effect | When to Use |
|---|---|---|---|
| SIGTERM | 15 | Graceful termination | First attempt, allows cleanup |
| SIGKILL | 9 | Forceful termination | Process ignoring SIGTERM |
| SIGINT | 2 | Interrupt (Ctrl+C) | Interactive programs |
| SIGQUIT | 3 | Quit with core dump | Debugging hung processes |
| SIGHUP | 1 | Hangup, reload config | Daemon configuration reload |
| SIGSTOP | 19 | Pause execution | Temporarily stop process |
| SIGCONT | 18 | Continue execution | Resume stopped process |
Prevention and best practices:
Important Notes:
- Always try SIGTERM first before SIGKILL to allow graceful shutdown
- Zombie processes can't be killed - you must kill their parent
- D state processes (uninterruptible sleep) require fixing the underlying I/O issue
- Use
kill -0to check if process exists without sending signal - Consider using
timeoutcommand to prevent processes from hanging indefinitely
3. Filesystem Operations & Permissions
Essential filesystem operations, permission management, and troubleshooting file-related issues.
Q: How to change file permissions and ownership?
SecurityDirect Answer:
Changing permissions (chmod):
Changing ownership (chown):
Understanding permission notation:
Common permission scenarios:
Default permissions with umask:
Advanced: ACLs (Access Control Lists):
Permission troubleshooting:
| Error | Check Command | Solution |
|---|---|---|
| "Permission denied" | ls -la file.txt |
chmod +x file.txt or chown user file.txt |
| Can't delete file | ls -ld directory/ |
Need write permission on directory, not file |
| Can't cd into directory | ls -ld directory/ |
Need execute permission on directory |
| Web server can't read file | ls -la /var/www/html/ |
Files need to be readable by www-data user or world-readable |
| Script won't execute | ls -la script.shcat script.sh | head -1 |
Need execute permission and correct shebang (#!) line |
Security Best Practices:
- Principle of Least Privilege: Give minimum permissions needed
- Use groups instead of world permissions: Better security control
- Avoid 777 permissions: Never use unless absolutely necessary
- Limit SetUID programs: Only essential system binaries should have this
- Regular permission audits: Find world-writable files with
find / -perm -0002 -type f 2>/dev/null - Use ACLs for complex permission needs: Instead of creating multiple groups
- Secure umask: Use 027 or 077 for sensitive environments
Q: How to find and delete files older than X days?
FilesystemDirect Answer:
Find files older than X days:
Delete files older than X days:
Practical cleanup scenarios:
Advanced find operations:
Cron jobs for automated cleanup:
Safety precautions:
| Precaution | Command | Purpose |
|---|---|---|
| Test first | find ... -print or -ls |
See what will be deleted before deleting |
| Use -ok instead of -exec | find ... -ok rm {} \; |
Prompt for confirmation on each file |
| Exclude important files | ! -name "*.sock" ! -name "*.pid" |
Don't delete socket or PID files |
| Limit scope | -maxdepth 2 |
Don't recurse too deeply |
| Log actions | ... -delete -print | tee logfile |
Keep record of what was deleted |
Critical Safety Tips:
- ALWAYS test with
-printor-lsbefore using-delete - Be careful with wildcards:
find / -type f -mtime +30searches entire filesystem! - Don't delete files in use: Check with
lsofif unsure - Consider archiving instead of deleting: Use
tarorgzip - Set up proper backups before running bulk deletions
- Use filesystem snapshots if available for easy recovery
4. Networking & Connectivity
Essential networking commands, troubleshooting connectivity issues, and network configuration.
Q: How to check network connectivity and diagnose issues?
NetworkingDirect Answer:
Step-by-step network troubleshooting:
Common network issues and solutions:
Network diagnostic script:
Essential networking commands reference:
| Task | Command | Purpose |
|---|---|---|
| Interface configuration | ip addr, ip link, ip route |
Modern interface management |
| Basic connectivity | ping, traceroute, mtr |
Test reachability and path |
| DNS resolution | dig, nslookup, host |
DNS troubleshooting |
| Port checking | telnet, nc, ss, netstat |
Check open/listening ports |
| Firewall | iptables, firewall-cmd, ufw |
Firewall configuration |
| Packet analysis | tcpdump, wireshark |
Deep packet inspection |
| Bandwidth testing | iperf, speedtest-cli |
Network performance testing |
| Network debugging | ss, netstat, sar -n |
Statistics and monitoring |
Network Layers Troubleshooting:
OSI Model troubleshooting approach:
- Physical Layer (Layer 1):
- Check cables, lights on network interface
- Command:
ip link show,ethtool eth0
- Data Link Layer (Layer 2):
- Check MAC address, VLANs, switches
- Command:
arp -a,ip neigh
- Network Layer (Layer 3):
- Check IP addresses, routing, ICMP
- Command:
ip addr,ip route,ping
- Transport Layer (Layer 4):
- Check TCP/UDP ports, connections
- Command:
ss,netstat,telnet
- Application Layer (Layer 7):
- Check DNS, HTTP, specific protocols
- Command:
dig,curl,nslookup
Quick Command Reference
Most Frequently Used Commands
| Category | Command | Purpose | Example |
|---|---|---|---|
| Files | ls |
List directory contents | ls -la |
| Files | find |
Search for files | find / -name "*.log" |
| Files | grep |
Search text | grep -r "error" /var/log |
| Process | ps |
Process status | ps aux | grep nginx |
| Process | kill |
Terminate process | kill -9 1234 |
| System | top |
Process viewer | top |
| System | df |
Disk free space | df -h |
| System | du |
Disk usage | du -sh /var |
| Network | ping |
Test connectivity | ping 8.8.8.8 |
| Network | netstat/ss |
Network statistics | ss -tulpn |
| Network | curl |
HTTP requests | curl -I http://example.com |
| Users | who |
Logged in users | who |
| Users | sudo |
Execute as root | sudo apt update |
| Text | cat |
Display file | cat file.txt |
| Text | tail |
End of file | tail -f log.txt |
| Text | vi/nano |
Text editors | vi file.txt |
DevOps-Specific Commands
| Tool | Command | Purpose | Example |
|---|---|---|---|
| Docker | docker ps |
List containers | docker ps -a |
| Docker | docker logs |
Container logs | docker logs -f container |
| Docker | docker exec |
Execute in container | docker exec -it bash |
| Kubernetes | kubectl get pods |
List pods | kubectl get pods -A |
| Kubernetes | kubectl logs |
Pod logs | kubectl logs pod-name |
| Kubernetes | kubectl describe |
Resource details | kubectl describe pod |
| Terraform | terraform init |
Initialize | terraform init |
| Terraform | terraform plan |
Show changes | terraform plan |
| Terraform | terraform apply |
Apply changes | terraform apply -auto-approve |
| Ansible | ansible-playbook |
Run playbook | ansible-playbook site.yml |
| Git | git status |
Check status | git status |
| Git | git log |
Show history | git log --oneline |
| Git | git diff |
Show changes | git diff HEAD~1 |
| AWS CLI | aws s3 ls |
List S3 buckets | aws s3 ls |
| AWS CLI | aws ec2 describe |
EC2 instances | aws ec2 describe-instances |
Common Interview Questions Quick Answers
Q: How to check running processes?
ps aux or top or htop
Q: How to find a file?
find /path -name "filename" or locate filename
Q: How to check disk space?
df -h for free space, du -sh /path for directory usage
Q: How to check memory usage?
free -h or top (press 'M' to sort by memory)
Q: How to check network connections?
ss -tulpn or netstat -tulpn
Q: How to search in files?
grep "pattern" file.txt or grep -r "pattern" /path
Q: How to view logs?
tail -f /var/log/syslog or journalctl -f
Q: How to kill a process?
kill PID (SIGTERM) or kill -9 PID (SIGKILL)
Q: How to check service status?
systemctl status servicename
Q: How to check listening ports?
ss -tulpn | grep LISTEN
Q: How to check CPU info?
lscpu or cat /proc/cpuinfo
Q: How to check kernel version?
uname -r or cat /proc/version
Q: How to check OS version?
cat /etc/os-release or lsb_release -a
Q: How to add user?
useradd username and passwd username
Q: How to schedule a task?
crontab -e to edit cron jobs
Q: How to archive files?
tar -czvf archive.tar.gz /path
Q: How to check file permissions?
ls -la file.txt
Q: How to change permissions?
chmod 755 file.txt or chmod u+rwx file.txt
Q: How to change ownership?
chown user:group file.txt