Linux Interview Questions
Linux Interview Questions
* It starts with root `/`. Key directories include `/bin`, `/etc`, `/home`,
`/var`, `/usr`, and `/tmp`.
* Absolute paths start from the root (`/`), while relative paths start from the
current directory.
* `ls`, `cd`, `pwd`, `mkdir`, `rm`, `cp`, `mv`, `cat`, `touch`, `chmod`, `chown`
10. **What is the `chmod`, `chown`, and `chgrp` command used for?**
* Three types: read (r), write (w), execute (x) for user, group, others.
Permissions can be changed using symbolic or numeric mode.
12. **What are hidden files and how to list them?**
* Files starting with `.` are hidden. Use `ls -a` to view them.
14. **How do you check the current disk usage and free space?**
* Symbolic link is like a shortcut. Hard link points directly to the inode.
---
* BIOS -> Bootloader (GRUB) -> Kernel -> `init`/`systemd` -> Login
* It defines how disk partitions, filesystems, and devices are mounted at boot.
14. **What is the use of `top`, `htop`, `vmstat`, `free`, and `iostat`?**
---
* `fork()` creates a child process. `exec()` replaces the process image with a
new one.
* A zombie process is dead but still in the process table. Kill the parent
process to clean it.
* Soft: returns an error if server not reachable; Hard: keeps retrying until
server responds.
12. **What is `grep`, `awk`, and `sed` used for? Provide examples.**
* With I/O schedulers like CFQ, Deadline, and NOOP, tunable via `/sys` or
`ionice`
---
```bash
find . -type f -exec du -h {} + | sort -rh | head -n 1
```
2. **How do you write a script to monitor disk space and send alerts?**
```bash
#!/bin/bash
THRESHOLD=80
USAGE=$(df / | grep / | awk '{ print $5 }' | sed 's/%//g')
if [ $USAGE -gt $THRESHOLD ]; then
echo "Disk space alert: Usage is at $USAGE%" | mail -s "Disk Alert"
[email protected]
fi
```
4. **Explain the use of `set -e`, `set -x`, and `set -u` in Bash.**