π Complete Linux Interview Guide: From Basics to Advanced
Master Linux Interviews with Real-World Q&A β From Basics to Advanced Topics!
πΉ Introduction
Welcome to the ultimate Linux interview guide! Whether you're a beginner or an advanced user, this guide covers everything you need to ace your Linux interview. You'll find essential commands, real-world scenarios, and practical examples. π‘
1) π What is Linux? and Explain Features of Linux
π What is Linux?
Linux is a free, open-source, and highly secure operating system used on servers, desktops, and cloud platforms. It is known for its stability, flexibility, and performance, making it a top choice for DevOps, cloud engineers, and developers. π»π
π₯ Key Features of Linux
π 1οΈβ£ Open-Source & Free
Linux is completely free to use, modify, and distribute, unlike Windows or macOS. You can customize it as per your needs.
π₯ 2οΈβ£ Multi-User Support
Multiple users can access the same system without interfering with each otherβs files or processes.
βοΈ 3οΈβ£ Multi-Tasking
Linux efficiently handles multiple processes at the same time, making it perfect for servers and development.
π 4οΈβ£ High Security (π Main Advantage!)
Linux is one of the most secure operating systems, making it less vulnerable to viruses and malware. Here's why:
β User Permissions & Role-Based Access β By default, Linux does not allow normal users to execute system-level changes, reducing the risk of malware infections.
β No Need for Antivirus (Unlike Windows!) β Linux doesnβt require traditional antivirus software because:
π‘οΈ Limited Root Access β Viruses cannot modify system files without admin permission.
π Frequent Security Patches β The open-source community quickly fixes vulnerabilities.
π« Executable Restrictions β Files are not executable by default unless explicitly given permission.
π Package Managers & Repositories β Software is installed from official, secure sources (like
apt
for Ubuntu), reducing the risk of malware.
β
Firewall & Network Security β Linux has built-in firewall tools (iptables
, ufw
) to block unauthorized access and prevent cyber threats.
β Open-Source Advantage β Because the Linux code is public, security vulnerabilities are found and fixed faster than in proprietary systems like Windows.
πΉ Conclusion: Linux is inherently more secure than Windows due to strong user permissions, package management, and open-source security monitoringβso antivirus software is generally not needed! ππ
π»5οΈβ£Powerful Command-Line Interface (CLI)
Linux provides a robust terminal that supports automation, scripting, and DevOps tools.
π¨βπ» 6οΈβ£Developer-Friendly
Supports multiple programming languages like Python, Java, C++, and Shell scripting, making it ideal for developers.
π€ 7οΈβ£ Active Community Support
A large, global community helps with troubleshooting, updates, and new features.
2)ποΈ Linux Architecture (Explained in Simple Terms)
Linux follows a layered architecture, meaning each part has a specific role. Letβs break it down in the simplest way possible! π
π₯οΈ 1οΈβ£ Hardware Layer
This is the physical part of your computer, including:
πΉ CPU (Processor)
πΉ RAM (Memory)
πΉ Hard Disk (Storage)
πΉ Network & Other Devices
π§ 2οΈβ£ Kernel (The Brain of Linux!)
The kernel is the heart of Linux. It acts as a bridge between hardware and software. It does:
β
Memory Management β Controls how much RAM a program can use.
β
Process Management β Manages running applications and assigns CPU time.
β
Device Management β Communicates with hardware like keyboards, mice, and printers.
β
Security & Permissions β Controls who can access what in the system.
π» 3οΈβ£ Shell (Your Command Helper)
The shell is a translator between you and the kernel. When you type commands in the terminal, the shell sends those instructions to the kernel.
πΉ Examples of shells: Bash, Zsh, Fish
π Example:
When you type ls
, the shell asks the kernel to list files, and the kernel fetches the result from storage.
π’ 4οΈβ£ User Applications (What You Use Daily)
This is where you interact with Linux! These are GUI or command-line programs like:
π₯οΈ Browsers β Firefox, Chrome
π File Managers β Dolphin, Nautilus
π Text Editors β Vim, Nano, VS Code
π» Command-Line Tools β grep
, awk
, sed
Note: πLet's understand how Linux processes a request from a user application to hardware using a step-by-step flow. This follows the User Application β Shell β Kernel β Hardware model.
β1οΈβ£ User Application Sends a Request The application (Terminal) ex. ls /home/user sends this request to Shell.
β 2οΈβ£ Shell Processes the Request π **Shell interprets the command (ls /home/user
) and sends it to the Kernel for execution. ex . User β Shell: "Find files in /home/user"
β 3οΈβ£ Kernel Communicates with Hardware
π Kernel checks storage (Hard Disk) and fetches the required data.
π Kernel sends the request to the hardware (Storage/Memory) to retrieve files.
β 4οΈβ£ Hardware Responds to Kernel
π The hardware (Hard Disk) finds the data and returns it to the kernel.
β 5οΈβ£ Kernel Sends Data Back to Shell
π Kernel processes the received data and passes it back to the Shell.
β 6οΈβ£ Shell Displays Output in User Application
π Shell sends the result back to the terminal, and you see the file list on the screen.
3)π Essential Linux Commands Cheat Sheet
Linux commands help you navigate, manage files, users, processes, networks, and storage efficiently. Here's a well-structured list to boost your Linux skills! π‘
π 1. Basic File & Directory Commands
π These commands help you navigate and manage files.
Command | Description |
pwd | Show current directory |
ls | List files & folders |
cd folder_name | Change directory |
mkdir new_folder | Create a folder |
rm file.txt | Delete a file |
rm -r folder_name | Delete a folder |
cp file1 file2 | Copy files |
mv file.txt /path/ | Move a file |
mv old_name new_name | Rename a file |
cat file.txt | View file content |
echo "Hello" | Display text/output |
whoami | Show logged-in user |
π 2. File & Directory Management
π For advanced file operations, use these commands.
Command | Description |
ls -lh | List files with size |
find / -name file.txt | Search for a file |
grep "error" logfile.log | Find text in a file |
diff file1 file2 | Compare files |
tar -cvf backup.tar /data | Create an archive |
tar -xvf backup.tar | Extract an archive |
π₯ 3. User & Permission Management
π Manage users, passwords, and permissions easily.
Command | Description |
useradd akshay | Add a new user |
passwd akshay | Set user password |
usermod -aG sudo akshay | Grant sudo access |
deluser akshay | Delete a user |
chmod 755 script.sh | Set file permissions |
chown akshay:users file.txt | Change file owner |
ls -l | View file permissions |
βοΈ 4. Process Management
π Manage running processes and system performance.
Command | Description |
ps aux | List running processes |
top | Show system resource usage |
kill -9 PID | Kill a process |
pkill -f process_name | Kill a process by name |
π 5. Networking in Linux
π Check network status, connections, and debugging.
Command | Description |
ifconfig / ip a | Show network interfaces |
ping google.com | Test network connectivity |
netstat -tulnp | Show open ports |
traceroute google.com | Trace route to a site |
nslookup google.com | DNS lookup |
πΎ 6. Disk & Storage Management
π Monitor disk space, partitions, and mounting.
Command | Description |
df -h | Monitor storage with and free up space. |
du -sh /folder | Check folder size |
mount /dev/sdb1 /mnt | Mount a partition |
umount /mnt | Unmount a partition |
π€ 7. Automation with Shell Scripting
π‘ Automate repetitive tasks using shell scripts and cron jobs.
πΉ Basic Shell Script
A simple script to print a message:
#!/bin/bash
echo "Hello, Akshay! Welcome to Linux."
π Save it as script.sh
, then run:
bash script.sh
πΉ Automate Tasks with Cron Jobs
Cron Jobs run tasks automatically at scheduled times.
Command | Description |
crontab -e | Edit cron jobs |
crontab -l | List existing cron jobs |
π Example: Run a script daily at 2 AM
0 2 * * * /path/to/script.sh
π 8. Advanced Linux Topics
π Log Management
Monitor system logs for errors and debugging.
Command | Description |
tail -f /var/log/syslog | View live logs |
journalctl -u nginx | Check service logs |
β Use Case: Helps track system events and troubleshoot issues.
π Performance Monitoring
Monitor system performance & resource usage.
Command | Description |
htop | Interactive process monitor |
iotop | Show disk I/O usage |
free -m | Check RAM usage |
β Use Case: Identify performance bottlenecks and optimize system resources.
4)π Linux Directory Structure (19 Important Directories)
Below is a table format for a clear and structured view of the Linux directory system:
π Directory | π Description | π Example Files |
/ (Root) | The top-level directory, everything starts here. | All other directories are inside / |
/bin (Binaries) | Essential system commands for all users. | ls , cp , mv , rm , cat |
/sbin (System Binaries) | Administrative commands for root users. | fdisk , iptables , reboot |
/boot (Boot Files) | Stores kernel & bootloader files. | vmlinuz , grub/ |
/dev (Devices) | Virtual files for hardware devices. | /dev/sda (disk), /dev/tty (terminal) |
/etc (Configuration Files) | System-wide configuration files. | /etc/passwd , /etc/fstab |
/home (User Home Directories) | Personal files for each user. | /home/akshay/ |
/lib (Libraries) | Shared libraries for system programs. | libc.so .6 |
/mnt (Mount Directory) | Manually mounted drives & partitions. | mount /dev/sdb1 /mnt |
/media (Removable Media) | Auto-mounts USB, CD/DVD, etc. | /media/usb-drive/ |
/opt (Optional Software) | Manually installed third-party software. | /opt/google/chrome/ |
/proc (Process & Kernel Info) | Virtual directory with system info. | /proc/cpuinfo , /proc/meminfo |
/root (Root User Home) | Home directory for the superuser. | /root/ |
/run (Runtime Data) | Temporary system data after boot. | /run/systemd/ |
/srv (Service Data) | Data for services like web servers. | /srv/http/ |
/sys (System & Hardware Info) | Kernel & hardware-related files. | /sys/class/net/ |
/tmp (Temporary Files) | Temporary files, deleted on reboot. | Web browser downloads |
/usr (User Programs & Data) | User-installed programs & docs. | /usr/bin/ , /usr/share/ |
/var (Variable Data) | Logs, caches, mail, and more. | /var/log/syslog , /var/www/html/ |
5) π€ System User (Root) vs Standard User in Linux
Linux has two main types of users:
π₯ 1. System User (Root User) β The Super Boss!
β Full control over the system.
β Can install, modify, or delete anything.
β Can create and manage users.
π₯ 2. Standard User β The Safe Player!
β Limited access β Can use the system but can't modify core files.
β Can create, edit, and delete personal files.
β Cannot install software without root permission.
β Safer because mistakes wonβt break the system.
6)π Types of Web Services β Explained Simply!
Web services help apps talk to each other over the internet. But how they are built matters a lot! Letβs explore the 4 main types of web service architectures.
π 1. Monolithic Architecture β The One Big Block
π‘ "All-in-One" System β Everything (UI, logic, database) is in one large codebase.
β Easy to develop initially but β hard to scale & update.
π₯ Example: A traditional e-commerce website where all features run inside one big app.
π 2. Microservices Architecture β The Flexible System
π‘ "Break it Down" Approach β The app is split into small independent services.
β Scalable, Faster updates but β needs good coordination.
π₯ Example: Netflix β Different services for movies, payments, and recommendations.
π₯ 3. Extended Architecture β Hybrid Power
π‘ "Mix of Monolithic & Microservices" β Some parts remain monolithic, while others go microservices.
β Best of both worlds but β can be complex to manage.
π₯ Example: A banking app where core functions (transactions) are monolithic, but extra features (chat, notifications) use microservices.
βοΈ 4. Serverless Architecture β No Server Worries!
π‘ "Pay-as-you-go" Model β Code runs only when needed, no need to manage servers.
β Cost-efficient & auto-scales but β depends on cloud providers.
π₯ Example: AWS Lambda-based apps β Runs only when a user logs in or uploads a file.
π― Which One is Best?
β
Monolithic β Best for small apps or startups.
β
Microservices β Ideal for scalable, large applications.
β
Extended β Good for migrating old systems.
β
Serverless β Perfect for event-driven & cost-saving applications.
7) π The OSI Model β Explained Simply! π
Ever wondered how the internet works? How does a simple Google search or a WhatsApp message travel across the world? π
Meet the OSI Model β a 7-layer system that helps devices communicate smoothly over networks! π‘
The OSI model is like a courier service π¦ β each layer handles a specific task to deliver your data safely!
π₯ The 7 Layers of OSI Model & Their Purpose
π· Layer | π Purpose | π‘ Example |
7οΈβ£ Application Layer | User interacts with apps | Web browsers, Email (HTTP, FTP, SMTP) |
6οΈβ£ Presentation Layer | Converts data (encryption, compression) | SSL encryption, Data formats (JPEG, MP3) |
5οΈβ£ Session Layer | Manages connection between devices | Login sessions, API calls |
4οΈβ£ Transport Layer | Ensures reliable data delivery | TCP (guaranteed), UDP (fast, no guarantee) |
3οΈβ£ Network Layer | Finds the best route for data | IP addresses, Routers, Packets |
2οΈβ£ Data Link Layer | Handles error-free data transfer | MAC addresses, Switches, Ethernet |
1οΈβ£ Physical Layer | Transfers actual bits (0s & 1s) | Cables, Wi-Fi, Bluetooth |
π΅οΈ How Data Travels in OSI Model?
πΉ When you send a message, it moves down all layers.
πΉ The receiverβs device moves it back up the layers to understand it.
π Example:
1οΈβ£ You send a message on WhatsApp.
2οΈβ£ The OSI layers break it into packets & transmit it.
3οΈβ£ The receiver's phone reconstructs the message via OSI layers.
8) π₯οΈ Essential Linux Questions & Answers π
π 1. How to Check Computer Name & Hostname in Linux?
Use the following commands:
hostname # Displays the current hostname
cat /etc/hostname # Shows the systemβs hostname file
π Tip: The hostnamectl
command gives more details like OS and kernel version.
π 2. What is the Difference Between Relative and Absolute Path?
β
Absolute Path: Full path starting from the root (/
).
π Example: /home/akshay/docs/file.txt
β
Relative Path: Path relative to the current location.
π Example: ./docs/file.txt
(if you're in /home/akshay
)
π 3. How to Check File Permissions in Linux?
Run:
ls -l file.txt
Output:
-rwxr--r-- 1 user user 1234 Jan 01 12:00 file.txt
π Tip: Use stat file.txt
for detailed file permissions.
π 4. How to Check the IP of Your Linux Server?
ip a # Show all IP addresses
hostname -I # Show only the IP address
π Tip: Use ifconfig
if ip a
is not available.
π 5. Which Command is Used to Find Files in Linux?
find / -name "file.txt" # Search for a file by name
locate file.txt # Faster search (needs updatedb first)
π Tip: Use grep
inside find
to filter results.
π 6. What are the Different Types of File Permissions in Linux?
Permission | Symbol | Description |
Read | r (4) | View file content |
Write | w (2) | Modify file content |
Execute | x (1) | Run the file as a program |
π Tip: Change permissions using chmod
and ownership using chown
.
7.π Linux Skeleton Files Explained β .bashrc, .bash_profile, .bash_logout & More!
Ever wondered why your Linux terminal behaves a certain way every time you log in? The secret lies in skeleton files β hidden configuration files that control your environment settings, commands, and scripts when you start a session.
Letβs explore the most important skeleton files in Linux! π
π What are Skeleton Files?
Skeleton files are default configuration files that get copied to a new userβs home directory when the account is created. They help define the user environment, including shell behavior, aliases, and login/logout scripts.
π Location of Skeleton Files:
/etc/skel/ # Default directory containing skeleton files
When a new user is created using useradd
, these files are copied to /home/username/
.
π Important Skeleton Files in Linux
File Name | Purpose |
~/.bashrc | Runs when a user opens a new shell. Defines aliases, environment variables, and functions. |
~/.bash_profile | Runs once at login. Loads .bashrc , sets PATH, and initializes environment settings. |
~/.bash_logout | Runs when a user logs out. Cleans up temp files or logs. |
. (Single Dot) | Refers to the current directory. Used in file paths and sourcing scripts. |
.. (Double Dot) | Refers to the parent directory. Helps navigate backward in directories. |