03 Linux Commands & Scripting - gannurohith/devops-interview-wiki GitHub Wiki
Topic 3: Linux Basics to Intermediate (Video Sessions 01, 02, 03) π Level: Suitable for a 5-year experienced DevOps/QA Engineer π Coverage: Shell commands, scripting, file system, permissions, processes, logs, troubleshooting
πΉ Section A β Basic to Intermediate Commands (8 Qs) Q: What's the difference between > and >> in shell redirection? A: > overwrites the file. >> appends output to the file.
Q: How would you find all .log files larger than 50MB in /var and delete them? A:
bash Copy Edit find /var -name "*.log" -size +50M -exec rm -f {} ; Q: What does the df -h vs du -sh command show? A: df -h shows disk space of file systems. du -sh shows space used by a directory or file.
Q: Whatβs the difference between hard link and soft link? A: Hard links share inode; deleting original file wonβt affect it. Soft links (symlinks) point to the path; break if target is removed.
Q: How do you check which process is using a specific port? A:
bash Copy Edit sudo lsof -i :
netstat -tulnp | grep Q: Explain the use of /etc/fstab. A: Stores static file system mount configurations that persist across reboots.
Q: How do you list only the directory names in /var/log? A:
bash Copy Edit ls -l /var/log | grep ^d Q: How do you monitor real-time log updates in Linux? A:
bash Copy Edit tail -f /var/log/syslog # or any log file πΉ Section B β User Management & Permissions (5 Qs) Q: What does chmod 755 mean? A: rwxr-xr-x β owner has full rights; group and others have read/execute.
Q: How would you add a new user and give sudo access? A:
bash
Copy
Edit
useradd rohit && passwd rohit
usermod -aG sudo rohit
Q: How do you set password expiry for a user account?
A:
bash Copy Edit chage -M 30 rohit Q: How do you check the default shell of a user? A:
bash Copy Edit grep rohit /etc/passwd Q: How would you recursively change ownership of files in /opt/app to rohit? A:
bash Copy Edit chown -R rohit:rohit /opt/app πΉ Section C β Process & Job Management (5 Qs) Q: Difference between foreground & and background jobs (bg, fg, jobs)? A: & starts a background process. jobs lists them, fg brings to foreground, bg resumes stopped jobs.
Q: How do you find high CPU-consuming processes? A:
bash Copy Edit top # or ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head Q: How do you kill a zombie process? A: Zombies can't be killed directly. Kill the parent process using kill -9 .
Q: How to run a script every day at 3 AM? A:
bash Copy Edit crontab -e
0 3 * * * /path/to/script.sh Q: How do you limit memory usage of a process? A: Use ulimit or use cgroups.
πΉ Section D β Scripting and Automation (8 Qs) Q: Write a script to check if a service is running, and restart if it's not. A:
bash Copy Edit #!/bin/bash service_name="nginx" if ! systemctl is-active --quiet $service_name; then echo "$service_name is down, restarting..." systemctl start $service_name fi Q: How do you get input from a user and print a message in a script? A:
bash Copy Edit read -p "Enter your name: " name echo "Hello, $name" Q: What is the difference between [ and [[ in bash? A: [[ is more robust and supports regex. [ is POSIX compliant.
Q: How do you pass arguments to a shell script? A:
bash Copy Edit ./script.sh arg1 arg2
Q: How to redirect both stdout and stderr to the same file? A:
bash Copy Edit command > output.log 2>&1 Q: How would you compare two numbers in a bash script? A:
bash Copy Edit if [ $a -gt $b ]; then echo "a > b"; fi Q: How do you loop through a list of files and delete them? A:
bash Copy Edit for file in *.tmp; do rm -f "$file"; done Q: How do you make a script executable and run it? A:
bash
Copy
Edit
chmod +x script.sh
./script.sh
πΉ Section E β Logs, Debugging, Boot, Kernel (4 Qs)
Q: How do you check boot logs in Linux?
A:
bash
Copy
Edit
dmesg | less
journalctl -b
Q: How do you monitor file system changes in real time?
A:
bash Copy Edit inotifywait -m /some/path Q: How do you increase swap memory in Linux? A:
bash Copy Edit dd if=/dev/zero of=/swapfile bs=1G count=4 chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile Q: How to check the current kernel version and OS details? A:
bash
Copy
Edit
uname -r
cat /etc/os-release