0% found this document useful (0 votes)
3 views5 pages

Linux Interview Questions

The document provides a comprehensive list of basic, intermediate, and advanced Linux interview questions and answers. Topics covered include the Linux operating system, file system hierarchy, commands, process management, system initialization, and scripting. It serves as a resource for individuals preparing for Linux-related job interviews.

Uploaded by

shinde09kanak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Linux Interview Questions

The document provides a comprehensive list of basic, intermediate, and advanced Linux interview questions and answers. Topics covered include the Linux operating system, file system hierarchy, commands, process management, system initialization, and scripting. It serves as a resource for individuals preparing for Linux-related job interviews.

Uploaded by

shinde09kanak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

### Basic Linux Interview Questions & Answers

1. **What is Linux? How is it different from Unix?**

* Linux is an open-source, Unix-like operating system based on the Linux kernel.


Unlike Unix, Linux is free, community-developed, and can run on a wide variety of
hardware.

2. **What are the basic components of Linux?**

* Kernel, Shell, File System, System Libraries, and Utilities.

3. **What is the Linux file system hierarchy?**

* It starts with root `/`. Key directories include `/bin`, `/etc`, `/home`,
`/var`, `/usr`, and `/tmp`.

4. **What is the difference between absolute and relative paths in Linux?**

* Absolute paths start from the root (`/`), while relative paths start from the
current directory.

5. **What are some commonly used Linux commands?**

* `ls`, `cd`, `pwd`, `mkdir`, `rm`, `cp`, `mv`, `cat`, `touch`, `chmod`, `chown`

6. **How do you view the contents of a file in Linux?**

* Using `cat`, `less`, `more`, `head`, or `tail` commands.

7. **What is the use of `ls`, `cd`, `pwd`, `mkdir`, and `rmdir`?**

* `ls`: list files


* `cd`: change directory
* `pwd`: print working directory
* `mkdir`: create directory
* `rmdir`: remove empty directory

8. **What is a shell in Linux?**

* A shell is a command-line interpreter that allows users to interact with the


system.

9. **What is the difference between `sh`, `bash`, and `zsh`?**

* `sh`: Bourne shell (original)


* `bash`: Bourne Again SHell (default in many systems)
* `zsh`: Z shell with more features

10. **What is the `chmod`, `chown`, and `chgrp` command used for?**

* `chmod`: change file permissions


* `chown`: change file owner
* `chgrp`: change group ownership

11. **How do file permissions work in Linux?**

* 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.

13. **What is the difference between `>` and `>>` in Linux?**

* `>`: overwrites file content


* `>>`: appends to the file

14. **How do you check the current disk usage and free space?**

* `df -h` (disk free), `du -sh *` (directory size)

15. **What is a symbolic link vs hard link?**

* Symbolic link is like a shortcut. Hard link points directly to the inode.

---

### Intermediate Linux Interview Questions & Answers

1. **What is a process in Linux? How do you manage processes?**

* A process is a running instance of a program. Managed using `ps`, `top`,


`kill`, `nice`, `renice`, etc.

2. **How to find the process ID (PID) of a running program?**

* Use `ps aux | grep program_name` or `pidof program_name`

3. **What is the difference between a process and a thread?**

* A process is independent; a thread is a subset of a process sharing memory.

4. **What is `cron` and how does it work?**

* `cron` is a time-based job scheduler. It runs jobs from `crontab` files.

5. **How do you schedule a job in Linux using `crontab`?**

* Use `crontab -e` and define in format: `* * * * * /path/to/script`

6. **Explain the boot process of a Linux system.**

* BIOS -> Bootloader (GRUB) -> Kernel -> `init`/`systemd` -> Login

7. **What is `init` vs `systemd`?**

* `init` is the traditional system initializer. `systemd` is the newer, faster


alternative.

8. **What is the use of `/etc/fstab`?**

* It defines how disk partitions, filesystems, and devices are mounted at boot.

9. **How do you mount and unmount a filesystem?**

* `mount /dev/sdX /mnt`, `umount /mnt`


10. **What are runlevels in Linux?**

* Predefined states of the system (e.g., 0 = halt, 3 = multi-user, 5 = GUI).


Replaced by `targets` in systemd.

11. **How do you check logs in Linux?**

* Use `journalctl`, `dmesg`, or view files in `/var/log/`

12. **How do you check open ports and listening services?**

* Use `netstat -tulpn`, `ss -tuln`, or `lsof -i`

13. **What is `iptables` and how is it used for firewall configuration?**

* `iptables` manages network packet filtering and firewall rules.

14. **What is the use of `top`, `htop`, `vmstat`, `free`, and `iostat`?**

* Monitoring tools for processes, memory, CPU, and disk I/O.

15. **How do you set environment variables in Linux?**

* Temporarily: `export VAR=value`


* Permanently: Add to `.bashrc`, `.profile`, or `/etc/environment`

---

### Advanced Linux Interview Questions & Answers

1. **What is the difference between `fork()` and `exec()`?**

* `fork()` creates a child process. `exec()` replaces the process image with a
new one.

2. **What is a zombie process and how do you kill it?**

* A zombie process is dead but still in the process table. Kill the parent
process to clean it.

3. **What is SELinux and how does it work?**

* Security-Enhanced Linux provides access control policies for system security.

4. **Explain how Linux handles memory management.**

* Uses paging, swapping, virtual memory, and caching.

5. **What is the use of the `lsof` command?**

* Lists open files and the processes using them.

6. **What is the difference between soft and hard mounts in NFS?**

* Soft: returns an error if server not reachable; Hard: keeps retrying until
server responds.

7. **Explain `strace` and when you would use it.**


* Traces system calls and signals. Used for debugging or understanding program
behavior.

8. **What is inodes in Linux and how are they used?**

* Inodes store metadata about files (permissions, size, etc.)

9. **What are sticky bits, SUID, and SGID?**

* Sticky bit: only owner can delete file in dir.


* SUID: runs file with owner's privileges.
* SGID: new files inherit group.

10. **How do you troubleshoot performance issues on a Linux system?**

* Use `top`, `iotop`, `vmstat`, `dstat`, `sar`, `journalctl`

11. **How do you monitor file changes in real-time?**

* Use `inotify`, `watch`, or `auditd`

12. **What is `grep`, `awk`, and `sed` used for? Provide examples.**

* `grep`: search text (`grep 'pattern' file`)


* `awk`: pattern scanning (`awk '{print $1}' file`)
* `sed`: stream editor (`sed 's/old/new/' file`)

13. **How does Linux handle I/O scheduling?**

* With I/O schedulers like CFQ, Deadline, and NOOP, tunable via `/sys` or
`ionice`

14. **What is a kernel panic and how do you troubleshoot it?**

* A fatal error in the kernel. Check `/var/log/kern.log`, dmesg, or hardware


issues.

15. **Explain the concept of cgroups and namespaces in Linux containers.**

* Cgroups: control resource usage (CPU, memory)


* Namespaces: isolate processes (PID, net, mount)

---

### Linux Scripting & DevOps-Related

1. **Write a Bash script to find the largest file in a directory.**

```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
```

3. **What is the difference between `#!/bin/sh` and `#!/bin/bash`?**

* `sh` is POSIX compliant shell, `bash` includes extended features (arrays,


brace expansion, etc.)

4. **Explain the use of `set -e`, `set -x`, and `set -u` in Bash.**

* `-e`: exit on error


* `-x`: print commands as executed
* `-u`: error on undefined variables

5. **How do you pass arguments to a shell script?**

* `$1`, `$2`, ..., `$@`, `$#` are used to access arguments.

6. **What is the purpose of `.bashrc`, `.bash_profile`, and `.profile`?**

* `.bashrc`: executed for interactive non-login shells


* `.bash_profile`: login shell setup
* `.profile`: generic POSIX equivalent

7. **What is the difference between a script and a command alias?**

* Script: file containing commands


* Alias: shortcut defined in shell (`alias ll='ls -la'`)

You might also like