πŸš€ Complete Linux Interview Guide: From Basics to Advanced

πŸš€ Complete Linux Interview Guide: From Basics to Advanced

Master Linux Interviews with Real-World Q&A – From Basics to Advanced Topics!

Β·

14 min read

πŸ”Ή 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.

CommandDescription
pwdShow current directory
lsList files & folders
cd folder_nameChange directory
mkdir new_folderCreate a folder
rm file.txtDelete a file
rm -r folder_nameDelete a folder
cp file1 file2Copy files
mv file.txt /path/Move a file
mv old_name new_nameRename a file
cat file.txtView file content
echo "Hello"Display text/output
whoamiShow logged-in user

πŸ“‚ 2. File & Directory Management

πŸ“Œ For advanced file operations, use these commands.

CommandDescription
ls -lhList files with size
find / -name file.txtSearch for a file
grep "error" logfile.logFind text in a file
diff file1 file2Compare files
tar -cvf backup.tar /dataCreate an archive
tar -xvf backup.tarExtract an archive

πŸ‘₯ 3. User & Permission Management

πŸ“Œ Manage users, passwords, and permissions easily.

CommandDescription
useradd akshayAdd a new user
passwd akshaySet user password
usermod -aG sudo akshayGrant sudo access
deluser akshayDelete a user
chmod 755 script.shSet file permissions
chown akshay:users file.txtChange file owner
ls -lView file permissions

βš™οΈ 4. Process Management

πŸ“Œ Manage running processes and system performance.

CommandDescription
ps auxList running processes
topShow system resource usage
kill -9 PIDKill a process
pkill -f process_nameKill a process by name

🌐 5. Networking in Linux

πŸ“Œ Check network status, connections, and debugging.

CommandDescription
ifconfig / ip aShow network interfaces
ping google.comTest network connectivity
netstat -tulnpShow open ports
traceroute google.comTrace route to a site
nslookup google.comDNS lookup

πŸ’Ύ 6. Disk & Storage Management

πŸ“Œ Monitor disk space, partitions, and mounting.

CommandDescription
df -hMonitor storage with and free up space.
du -sh /folderCheck folder size
mount /dev/sdb1 /mntMount a partition
umount /mntUnmount 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.

CommandDescription
crontab -eEdit cron jobs
crontab -lList 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.

CommandDescription
tail -f /var/log/syslogView live logs
journalctl -u nginxCheck service logs

βœ… Use Case: Helps track system events and troubleshoot issues.


πŸ“Š Performance Monitoring

Monitor system performance & resource usage.

CommandDescription
htopInteractive process monitor
iotopShow disk I/O usage
free -mCheck 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 LayerUser interacts with appsWeb browsers, Email (HTTP, FTP, SMTP)
6️⃣ Presentation LayerConverts data (encryption, compression)SSL encryption, Data formats (JPEG, MP3)
5️⃣ Session LayerManages connection between devicesLogin sessions, API calls
4️⃣ Transport LayerEnsures reliable data deliveryTCP (guaranteed), UDP (fast, no guarantee)
3️⃣ Network LayerFinds the best route for dataIP addresses, Routers, Packets
2️⃣ Data Link LayerHandles error-free data transferMAC addresses, Switches, Ethernet
1️⃣ Physical LayerTransfers 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?

PermissionSymbolDescription
Readr (4)View file content
Writew (2)Modify file content
Executex (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 NamePurpose
~/.bashrcRuns when a user opens a new shell. Defines aliases, environment variables, and functions.
~/.bash_profileRuns once at login. Loads .bashrc, sets PATH, and initializes environment settings.
~/.bash_logoutRuns 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.

Β