Linux Interview Questions

Top 50 Linux Interview Questions and Answers (2024)

Top 50 Linux Interview Questions and Answers (2024)

Top 50 Linux Interview Questions and Answers (2024)

Sep 13, 2024

Soumyata Singh

linux interview questions
linux interview questions
linux interview questions

Linux is a significant operating system in the world of devices and software. If you wish to become a successful IT professional, you probably cannot ignore its importance. Linux is used by 40.8% of websites. Undoubtedly, job opportunities for Linux professionals are likely to surge during the decade. 


If you’re worried about an upcoming interview or need validation for your skills, you’re at the right place. This blog covers the top 50 Linux interview questions to help you stand out for that job role you have your eyes on.  


Whether you are a fresher or an experienced professional, there’s something here for your knowledge. So, let’s dive right in.  


Did You Know?
Around 70-75% of recruiters use an ATS (Applicant Tracking System) for their hiring process. Make sure your resume isn’t lost in the trash. Increase your chances of getting hired by creating an ATS-friendly resume


Here’s a list of the most important Linux interview questions whose answers you should know:   


1. What is Linux? 


Linux is a Unix-like open-source operating system (OS) used worldwide. It's famous for being free, versatile, and secure. Its goal is simple—to provide a stable and affordable OS. Over the years, it has grown in popularity due to its flexibility. You can install it on almost any hardware platform, from servers to mobile devices. Let’s break down the basics of Linux to understand what makes it unique and essential. 


Linux: A Unix-like Open-source OS


Unix inspired Linux and functions similarly. It’s designed to be free for users, making it an excellent option for both personal and professional use. As an open-source system, anyone can modify and share it. This flexibility is why Linux is so popular. You might be asked about its roots, open-source nature, or unique advantages.  


Named After Linus Torvalds 


Linus Torvalds, a Finnish software engineer, created Linux in 1991. He developed it as a personal project, but it quickly gained traction. Today, it is widely used in servers, smartphones, and even supercomputers.  


Affordable and Accessible OS 


Linux aims to provide a cost-effective OS for everyone. It eliminates the need for expensive licenses, making it accessible to individuals, schools, and businesses. For example, large companies use Linux to save money on software expenses. It’s important to note how this OS has revolutionized the industry by offering a free yet powerful alternative. 


Compatible with Various Hardware Platforms 


One of Linux's strengths is its compatibility with different hardware platforms. Whether you're running a desktop, server, or mobile device, Linux can work efficiently on all. Many devices, like Android phones, run on Linux.  


2. What Are the Important Components Of the Linux System?  



Linux is made up of several vital components that work together to create a robust system. Understanding these elements is essential, especially if you're looking to emerge as a successful IT professional. Let's break down the three main components that make Linux operate smoothly.


Kernel: The Core of Linux 


The kernel is the heart of the Linux system. It controls hardware interaction, manages system resources, and executes essential functions. Whenever you open a program or file, the kernel ensures everything runs properly. In Linux interview questions, the kernel is a basic but crucial concept. It manages tasks like memory and CPU usage.


System Libraries: Enabling Functions Without Extra Permissions 


System libraries offer specialized functions to applications without requiring direct access to the kernel. This makes them efficient and safe. They act as intermediaries, helping programs run smoothly. You should know how libraries like GNU C Library (glibc) provide essential tools to developers. 


System Utility: Handling Specific Tasks 


System utilities perform everyday tasks on Linux. These utilities handle everything from file management to system monitoring. For instance, commands like ls or ps are system utilities used for listing files or checking processes. Since these are essential for day-to-day Linux use, you must be prepared for these questions.  


3. Explain File Permissions in Linux 


File permissions in Linux are crucial for system security and management. They define who can read, write, or execute a file. Understanding permissions could be one of crucial Linux interview questions, as it plays an important role in managing file access.


Categories of File Permissions


Linux file permissions are categorized into three main groups:  

  1. User (u): The owner of the file. As the file's creator, you can define your access level. 

  1. Group (g): A group of users who share file access. This allows you to set permissions for team members. 

  1. Others (o): Any user who doesn’t belong to the group or isn’t the owner.

Each file or directory has these three permission categories, ensuring proper control over who can interact with your files.


Types of Permissions


There are three basic permissions in Linux: 

  • Read (r): You can view the contents of the file. For directories, this allows you to list its contents. 

  • Write (w): You can modify or delete the file. In directories, this permission lets you add, rename, or delete files. 

  • Execute (x): You can run the file as a program. For directories, execute permission allows you to enter the directory. 



Understanding Permission Example


For instance, if a file has permissions rwxr-xr--, here's what it means:

  • User: Read, write, and execute (rwx), allowing full control.

  • Group: Read and execute (r-x), but not modify.

  • Others: Only read (r--), with no write or execute rights.

This layered permission system ensures that sensitive files are properly protected, and only the right users have access. 


4. What is the Difference Between CLI and GUI? 


In Linux, there are two primary ways to interact with the system: CLI and GUI. Understanding both is crucial as each has unique advantages depending on the task at hand. 


Command Line Interface (CLI)


The CLI, or Command Line Interface, allows you to interact with the system using text-based commands. With the CLI, you directly type instructions into a terminal to control the OS. CLI provides greater control, flexibility, and precision for users who know the commands. 


For example, typing ls lists the contents of a directory. It's fast, especially for repetitive tasks or managing servers. In fact, many Linux professionals prefer CLI for system administration because it’s less resource-intensive and highly scriptable.


Graphical User Interface (GUI)


GUI, or Graphical User Interface, uses graphical icons, menus, and visual indicators to help users interact with the system. If you’ve ever used a desktop environment like GNOME or KDE on Linux, you’ve used a GUI.


A GUI is more user-friendly and ideal for beginners. For instance, instead of typing ls, you simply click on folders to view contents. Although GUI requires more system resources, it simplifies complex tasks, making it easier to understand for those less familiar with command-based interaction.



Which One Should You Use?


The choice between CLI and GUI depends on your needs. For quick, automated tasks, CLI is the preferred choice. For visual clarity and ease of use, especially in desktop applications, GUI is the go-to option. 


5. What is the Difference Between Linux and Unix? 



Linux and Unix are often mentioned together, but they are not the same. Unix is an older operating system. It was designed for mainframe computers and is still used today in some commercial environments. Linux, on the other hand, is relatively new and open-source, meaning anyone can modify and distribute it freely.  


While both systems share similar commands and architecture, their key differences lie in licensing, cost, and development models. Unix is typically proprietary and expensive, while Linux is free and open to everyone.  


Linux is widely used across various platforms, from servers to mobile devices, whereas Unix is often limited to specific hardware. 



The major difference between Linux and Unix is how they are distributed and used in modern computing. Linux’s flexibility and cost-free model make it more accessible to individuals and businesses. Unix, while stable and robust, tends to be confined to enterprise-level solutions due to its cost and hardware dependencies.  


6. What is BASH?


BASH, or Bourne Again Shell, is a command language interpreter for Linux. It acts as an interface between you and the operating system, allowing you to run commands, scripts, and manage files. As a popular shell in Linux, understanding BASH is essential for anyone preparing for linux interview questions.


BASH as a Command Interpreter


BASH interprets the commands you type in the terminal. It processes these commands and instructs the system to execute them. For example, typing ls will list files in the current directory. BASH is efficient and lets you execute tasks quickly, making it a favorite for Linux administrators.


BASH Scripting


You can also use BASH to create scripts, which are essentially a series of commands stored in a file. These scripts help automate repetitive tasks. For example, a BASH script could be written to back up files daily or monitor system performance. BASH scripting is a core skill in Linux, helping to save time and reduce errors.


Key Features of BASH


  • History: BASH stores a history of previously executed commands, allowing you to rerun them easily with the history command. 

  • Command Line Editing: You can edit and correct commands directly on the terminal before executing them.

  • Job Control: BASH allows you to run and manage multiple processes simultaneously, either in the foreground or background. 


FeatureDescriptionHistory CommandAccess past commands (history)Job ControlRun processes in the background (bg, fg)AliasesShortcuts for common commands (alias)


BASH is widely used because it is free, powerful, and compatible with many Linux distributions. Whether you're a system administrator or a developer, BASH offers flexibility and control.


7. What is the Difference Between BASH and DOS?


BASH and DOS are both command-line interfaces, but they serve different operating systems and have significant differences. BASH is commonly used in Unix-like systems, including Linux, while DOS (Disk Operating System) is primarily associated with Windows. Understanding the key differences between these two is crucial.  


Here’s a comparison table for clarity: 



Let’s elaborate on this.  


Operating System Compatibility 


BASH is used in Unix-like systems such as Linux and macOS. While BASH continues to evolve and remains a crucial part of modern operating systems, DOS is largely obsolete, replaced by the Windows GUI. It is primarily found in older versions of Microsoft Windows, such as MS-DOS and Windows 95.   


Command Structure 


BASH commands are case-sensitive, meaning ls is different from LS. This offers more control and flexibility, while DOS simplifies command usage but limits potential options. Therefore, dir and DIR would perform the same function.  


Scripting Abilities 


DOS has limited scripting capabilities. However, BASH allows for complex scripting, making it ideal for automating tasks. BASH scripts can contain conditional statements, loops, and variables. DOS batch files are less powerful than BASH scripts, limiting automation.  


For developers or administrators, BASH scripting can automate repetitive tasks, while DOS remains less flexible for advanced automation.


Community and Support 


BASH benefits from an active and vast open-source community, ensuring continuous updates and security patches. DOS, on the other hand, is outdated and no longer receives support.


8. What is Shell in Linux? 


A shell in Linux is an interface between you and the operating system. It allows you to run commands, programs, and scripts by typing them in the terminal.  


Role of the Shell


The shell interprets the commands you input and tells the operating system what to do. For example, when you type mkdir newfolder, the shell creates a new directory called "newfolder." In this sense, the shell acts as the middleman between you and the OS. 


Types of Shells in Linux



Linux offers several types of shells, each with different features:


  • BASH (Bourne Again Shell): The most commonly used shell. It’s known for its flexibility and scripting capabilities. 

  • ZSH (Z Shell): An extended version of BASH with more features and customizability. 

  • KornShell (ksh): Another popular shell, often used in Unix systems for its scripting capabilities. 

  • Fish (Friendly Interactive Shell): Designed to be user-friendly and visually appealing. 


Shell vs Terminal


It’s common to confuse the shell with the terminal. The terminal is simply the program that opens the shell and allows you to interact with it. Think of the shell as the brain that processes commands and the terminal as the interface where you type those commands.


The shell is crucial for interacting with Linux at a deeper level, whether you're executing commands or writing scripts. 


9. What are Daemons? 


In Linux, daemons are background processes that run without user interaction. They typically handle system tasks and services like scheduling, logging, and network connections. daemons are crucial especially when managing services in Linux. 


How Daemons Work 


Daemons start running when the system boots and keep running in the background. They ensure essential services like web servers, printers, and system logs are functioning correctly. For example, sshd is a daemon that handles SSH connections. 


Common Daemons in Linux 


There are several well-known daemons that handle important system functions:


  • cron: Manages scheduled tasks like backups.

  • httpd: Handles web server tasks for Apache.

  • sshd: Manages secure shell (SSH) connections for remote logins. 


These daemons operate silently in the background to ensure smooth system performance. 


How Daemons Differ from Regular Processes


Regular processes terminate once a task is complete. Daemons, on the other hand, keep running to provide continuous service. They are started automatically and require little to no user input. 


10. Explain the Three Standard Streams in Linux 


In Linux, three standard streams are used for input and output between processes and programs. These streams are crucial in managing data flow and are often highlighted in linux interview questions. The three streams are standard input (stdin), standard output (stdout), and standard error (stderr). 


Standard Input (stdin) 


Standard input is used to provide input to a program. It typically comes from the keyboard but can also come from files or other sources. By default, stdin is represented by file descriptor 0.


For example, when you type cat and press enter, the data you input is read through stdin.


Standard Output (stdout) 


Standard output is where a program sends its output. By default, stdout is the terminal screen, and it is represented by file descriptor 1. If you run a command like ls, the list of files is sent to stdout, which then displays it on your terminal.


Standard Error (stderr) 


Standard error is where error messages from a program are sent. It helps separate normal output from error messages. Stderr uses file descriptor 2 and, like stdout, usually points to the terminal.


For example, if you try to access a non-existent file with cat missingfile.txt, the error message will be sent to stderr. 


Understanding these three streams is essential for effective input/output management in Linux.   


11. Explain the Linux File System Hierarchy 


The Linux file system hierarchy is structured to keep files and directories organized. Every file and directory is located within a single root directory, denoted by a forward slash /. 


Root Directory (/) 


The root directory is the topmost directory in Linux. All other directories and files stem from this root. It serves as the base of the entire file system.


  • /bin: The /bin directory contains essential binaries (programs) required for the system to function, such as basic commands like ls, cat, and cp. These binaries are available to all users.

  • /home: This is where user directories are stored. Each user gets a separate subdirectory under /home, such as /home/username. Files and personal data for each user reside here.

  • /etc: This directory holds configuration files. These files control the behavior of various programs and services. For instance, the network configuration files can be found here.

  • /var: The /var directory contains files that change frequently, such as logs, temporary files, and email spools. For example, /var/log holds system logs that administrators check regularly.

  • /usr: The /usr directory holds user-installed software and libraries. It includes subdirectories like /usr/bin for user binaries and /usr/lib for shared libraries.


A strong grasp of the Linux file system hierarchy will help you effectively manage files and directories.  


12. What is LILO?


LILO, which stands for Linux Loader, is a boot loader for Linux. It helps load the operating system into memory and start it. If you're studying for linux interview questions, understanding LILO can be crucial, especially in older systems. 


Role of LILO 


LILO is responsible for booting Linux systems from hard disks. It loads the kernel into memory and hands over control to the operating system. You can also use LILO to boot other operating systems alongside Linux. 


Features of LILO 


  • Customizable Boot Options: LILO allows you to configure multiple operating systems and set a default OS for booting. 

  • No Need for a File System: Unlike modern boot loaders, LILO doesn’t rely on a file system. It works directly with the BIOS to load the operating system. 

  • Versatility: LILO supports various hardware architectures, making it useful for diverse environments.  


LILO vs. GRUB 


LILO is often compared to GRUB (Grand Unified Bootloader). While LILO is simpler, GRUB offers more flexibility. For example, GRUB allows editing of boot parameters at startup, something LILO doesn’t provide.  



While LILO has been replaced by GRUB in most Linux distributions, it's still valuable to understand for interviews.


13. What is Swap Space? 


Swap space in Linux is a dedicated area on your hard disk used when your system’s RAM is full. It acts as virtual memory, allowing your system to handle larger workloads without crashing. Swap space is a common topic in linux interview questions, as it plays a crucial role in memory management. 


How Swap Space Works 


When your system runs out of physical RAM, it moves inactive pages of memory to swap space. This frees up RAM for more active processes. While swap space is slower than RAM, it provides a safety net during memory-intensive tasks. 


How Much Swap Space Do You Need? 


The amount of swap space you need depends on your system’s RAM and usage. A common rule is to allocate swap space equal to or double your RAM size. For instance, a system with 8GB of RAM might have 16GB of swap space. However, modern systems with more RAM typically require less swap.  


Swap Space vs RAM 


RAM is faster and directly used by active processes, while swap space is a backup. When your system uses too much swap space, it can lead to “swapping,” where the system becomes slow due to frequent memory transfers between RAM and swap.


14. Explain the Linux Directory Commands 



Linux directory commands help you manage and navigate through directories in the system. They are an essential part of working with Linux. Here are some of the most common directory-related commands. 


1. pwd – Print Working Directory


This command displays the current directory you are in. It is helpful when you need to check your location within the file system. 


2. ls – List Directory Contents


The ls command is used to list the contents of a directory. By default, it shows the names of files and directories in the current folder. 


3. cd – Change Directory


The cd command allows you to switch between directories. It’s one of the most commonly used Linux commands.


4. mkdir – Make Directory


mkdir command creates a new directory. This command is helpful when organizing files into specific folders.


5. rmdir – Remove Directory


The rmdir command is used to remove empty directories.



Mastering these basic directory commands will give you better control over the Linux filesystem.


15. What is the Difference Between Hard Links and Soft Links? 


In Linux, both hard and soft links serve as shortcuts or references to files. However, they operate differently and have distinct characteristics. Understanding these differences helps managing files effectively. 


Hard Links 


A hard link is a direct reference to the physical data of a file. When you create a hard link, you essentially create another file name that points to the same data on the disk.


  • Same inode number: Both the original file and the hard link share the same inode.

  • File size: Hard links do not take up additional space as they only point to the same data.

  • Deletion: Deleting the original file doesn't remove the data as long as a hard link exists.

  • Usage: You can use hard links for backup files or in cases where you want multiple file names for the same data. 


Example:  $ ln original.txt hardlink.txt


This command creates a hard link named hardlink.txt that points to original.txt. 


Soft Links (Symbolic Links) 


A soft link, or symbolic link, is a shortcut that points to the file name rather than the data.


  • Different inode number: A soft link has its own inode and points to the original file.

  • File size: Soft links take up minimal space as they only store the file path.

  • Deletion: Deleting the original file breaks the link, and the soft link becomes unusable.

  • Usage: Soft links are useful for linking files across different file systems or directories.


Example: $ ln -s original.txt softlink.txt 


This creates a symbolic link named softlink.txt that points to original.txt. 


16. How to Mount and Unmount Filesystems in Linux?


Mounting and unmounting filesystems in Linux is essential when working with external drives or different partitions. The process lets you access storage devices and manage them efficiently. This is also one of the commonly asked linux interview questions.


Mounting a Filesystem


To access the contents of a storage device, you must first "mount" it. This means attaching the device to a directory in the system.


  1. Check Available Filesystems Before mounting, you can view available devices using the lsblk or df -h command. 

Example: $ lsblk

  1. Mount Command: Use the mount command to attach the filesystem to a specific directory, known as a mount point.

Syntax: $ mount /dev/sdb1 /mnt

This command mounts the /dev/sdb1 partition to the /mnt directory.

  1. Creating a Mount Point: If the directory does not exist, you need to create it using mkdir. 

Example

$ mkdir /mnt/mydrive

$ mount /dev/sdb1 /mnt/mydrive

This will create the directory /mnt/mydrive and mount the device there.


Unmounting a Filesystem


Once you're done using a mounted device, you should "unmount" it to safely disconnect it from the system.


  1. Unmount Command: Use the umount command to detach the filesystem from the mount point. 

Syntax: $ umount /mnt 

This command unmounts the device from /mnt. 

  1. Check Mounted Filesystems: You can verify which filesystems are currently mounted using the df -h command. 

Example:  $ df -h


This shows all mounted filesystems and their usage.  


17. How to Find Where a File is Stored in Linux? 


Finding a file in Linux can be essential, especially if you don’t remember where you saved it. Several commands can help you locate files quickly. Let's explore how you can find where a file is stored using simple Linux commands. 


1. Using the find Command 


The find command allows you to search for files in directories based on conditions like name, size, or date.


Example: $ find / -name "file.txt"


This command searches for file.txt across the entire root directory /. You can specify any other directory if you know where the file might be located. 


2. Using the locate Command 


The locate command is another tool that helps you find files quickly by looking through a pre-built database of file locations. It’s faster than find but may not always have the latest file additions.


Example: $ locate file.txt


Make sure the locate command is up to date by running updatedb beforehand. 


3. Using the which Command 


The which command is used to find the location of executable files that are in your system's PATH.


Example: $ which bash


This command shows where the bash executable is stored, which could be helpful for locating installed programs. 


4. Using the whereis Command 


The whereis command can find the location of executables, source files, and manual pages for programs.


Example: $ whereis python


This will return all known locations for Python on your system, including executable and manual pages. 


5. Using the grep Command with ps (for Processes) 


If you are trying to locate a file being used by a process, you can combine grep with the ps command to list the process IDs and corresponding files.


Example: $ ps aux | grep myfile


This will show if myfile is being used by any active process on the system.  


Using these commands can help you quickly locate files on your Linux system.  


18. What are INODE and Process Id?  


In Linux, both INODE and Process ID (PID) play crucial roles in managing files and processes. 


INODE


An INODE is a data structure that stores information about a file or directory. It includes metadata such as file size, ownership, and permissions, but not the file name. Each file has a unique INODE number within a file system.


Example: When you list files with ls -i, you see their INODE numbers. For instance: 

$ ls -i

1234567 file1.txt 

Here, file1.txt has an INODE number of 1234567.

Process ID (PID)


A Process ID (PID) is a unique identifier assigned to each running process. It helps the system manage and track processes.


Example: To find the PID of a running process, you can use the ps command: 

$ ps -e | grep processname

1234 ?        00:00:05 processname 

Here, 1234 is the PID for processname.


19. Explain the Process States in Linux 


In Linux, processes can be in various states, reflecting their current status. Understanding these states is important for managing system processes, troubleshooting and optimizing system performance. 


1. Running (R)


A process is in the Running state when it is either executing or ready to execute. This state indicates that the process is actively using the CPU or is waiting to use the CPU.


Example: You can see running processes using the ps command: 

$ ps -e

  PID TTY          TIME CMD

  123 tty1     00:00:01 bash

  456 tty1     00:00:05 firefox 


Here, bash and firefox are in the Running state.


2. Sleeping (S)


A process is in the Sleeping state when it is waiting for an event, such as I/O completion. It is not currently using the CPU but remains in memory.


Example: Use ps to see processes in the Sleeping state: 

$ ps -e

  PID TTY          TIME CMD

  789 tty1     00:00:00 sleep 


The sleep process is waiting for a timeout or input.


3. Zombie (Z)


A Zombie process has completed execution but still has an entry in the process table. It’s waiting for its parent process to read its exit status.


Example: Check for zombie processes with: 

$ ps -e -o pid,stat,cmd | grep 'Z'

  234 Z+         [defunct] 


The defunct process is a Zombie.


4. Stopped (T)


A Stopped process has been halted, usually by a signal. It is not currently running but remains in the system.


Example: You can see stopped processes using ps: 

$ ps -e

  PID TTY          TIME CMD

  567 tty1     00:00:00 paused_process 


The paused_process is stopped. 


20. Explain Process Scheduling in Linux  


Process scheduling is how Linux determines which process runs at a given time. This ensures efficient multitasking, allowing the system to manage multiple processes smoothly.


What is Process Scheduling?


Linux uses process scheduling to allocate CPU time to running processes. Each process gets a share of the CPU based on its priority and the system’s scheduling algorithm. 


Types of Process Scheduling


  1. Preemptive Scheduling: Preemptive scheduling allows the system to interrupt a running process to allocate CPU time to another process. It ensures that high-priority processes get CPU time over lower-priority ones. 

  1. Non-preemptive Scheduling: In non-preemptive scheduling, a running process keeps control of the CPU until it voluntarily releases it or finishes. This is less common in modern Linux systems.


Process States


A process in Linux can be in various states during scheduling:


  • Running: Actively using the CPU.

  • Waiting: Waiting for an event or resource.

  • Stopped: Temporarily halted, usually by the user.


Scheduling Algorithms in Linux


Linux primarily uses two scheduling algorithms:


  • Completely Fair Scheduler (CFS): The CFS is the default scheduling algorithm in Linux. It assigns CPU time based on process priority and ensures fairness by distributing CPU time evenly among processes.  

  • Round-Robin Scheduling: In this method, processes are given fixed time slices to execute. Once their time slice ends, the next process in the queue gets a turn. This ensures that every process gets CPU time.


Priority and Nice Value


Process priority determines which process gets CPU time first. Linux allows users to modify process priority using the nice value, where a lower value gives the process higher priority.


Example: $ nice -n 10 processname


Here, the processname is assigned a lower priority because of the higher nice value. 


21. What is the Difference Between a Process and a Thread? 


Processes and threads are both essential components of system performance. They allow multitasking and parallel execution. Understanding the distinction between them is important when discussing system resources and task management. 


Process 


A process is an independent program in execution. Each process has its own memory space and system resources. Processes don't share memory with each other unless explicitly allowed.


For Example: When you open a text editor, it runs as a separate process with its own allocated memory and resources.


Important Points:

  • Independent memory allocation

  • Separate system resources

  • Requires inter-process communication (IPC) to share data  


Thread


A thread is a smaller execution unit within a process. Multiple threads can run in parallel inside a process, sharing the same memory and resources. Threads enable more efficient execution because they share data easily.


For Example: When a web browser opens multiple tabs, each tab could run as a thread within the same process, sharing memory but executing separately.


Important Points:

  • Shares memory with other threads in the same process

  • Lightweight and faster than processes

  • Easier communication between threads


Here’s a comparison table for better understanding: 



Processes and threads serve different purposes in system design. Processes are better for isolated tasks, while threads handle parallel tasks efficiently within a single process. 


22. How to List All the Processes Running In Linux?


Monitoring processes is crucial for system performance and resource management when using Linux. Being able to list all running processes is a common task and frequently asked in linux interview questions. You can use several commands to achieve this.


  • The ps Command: This command shows the current processes running in your session. To list all processes, use the ps -aux option.  

  • The top Command: It provides real-time updates of running processes. It displays CPU and memory usage, making it useful for monitoring system performance.  

  • The htop Command: htop is a more user-friendly version of top. It displays running processes with an easy-to-read interface and allows process management directly from the interface. 


You can use these commands accordingly to list processes and keep track of system activities. 


23. How to Find the Process Id (PID) Of a Running Process? 


Knowing how to find the Process ID (PID) is essential for managing processes in Linux. You can locate a PID using different commands, a skill frequently tested in linux interview questions.


  1. The ps Command: The ps command lists running processes. Combine it with the grep command to filter specific processes. 


Example:  ps -aux | grep process_name 


Replace process_name with the actual name of the process you're looking for. The output shows the process details, including its PID.


  1. The pidof Command: This command directly returns the PID of a process. It’s simpler for finding the PID of a specific program.  


Example:  pidof process_name 


This command shows the PID(s) associated with the running process.


  1. The pgrep Command: It searches for processes based on their name or other attributes. 


Example:  pgrep process_name 


It returns a list of PIDs matching the process name. 


Using these commands, you find the PID of a running process quickly.  


24. What is the strace Command? 


The strace command in Linux tracks system calls made by a process. It helps you understand how a program interacts with the kernel, making it a powerful debugging tool.  


What Does strace Do? 


strace intercepts and logs system calls. System calls are requests made by programs to the operating system for various services, such as file access or memory allocation.


Example: strace ls


This command shows every system call made by the ls command, including opening directories, reading files, and more. 


Why Use strace?


You use strace to identify issues with program execution. If a program fails or behaves unexpectedly, strace can show where it’s going wrong by revealing every system call it attempts. 


Common strace Options 


  • -o file_name: Outputs trace results to a file instead of the terminal.

  • -p pid: Attaches to a running process using its PID. 


Example: strace -o output.txt ls


This command saves the system call log of ls to output.txt. 


Practical Use Cases 


  • Troubleshooting failed system calls.

  • Monitoring file access issues.

  • Debugging processes that crash unexpectedly.


strace could be essential especially, when dealing with system-level issues.  


25. How to Troubleshoot Network Connectivity Issues In Linux? 


Network connectivity issues are common and can disrupt workflows. Here’s how to troubleshoot these issues in Linux.  


1. Check Network Interface Status 


Start by checking if your network interface is up and running.


Command:  ifconfig


Look for your network adapter (e.g., eth0 or wlan0) and ensure it has an IP address. If not, restart the network interface.


Example: sudo ifconfig eth0 up  


2. Test Connectivity with ping 


The ping command checks if your system can reach a specific server.


Example: ping google.com


If you receive responses, your internet is working. If not, there might be DNS or gateway issues. 


3. Check Routing Table With netstat 


Use netstat to verify your system’s routing table and default gateway settings.


Command:  netstat -rn


Make sure your default gateway is correctly set up. If not, you can configure it with the following command: 


sudo route add default gw <gateway_ip> eth0


4. Identify DNS Issues with nslookup 


Use nslookup to verify if the DNS server is resolving domain names correctly.


Example: nslookup google.com 


If this fails, your DNS configuration may be incorrect. Check /etc/resolv.conf to verify the DNS servers. 


5. Use traceroute for Network Path Analysis 


traceroute helps you track the path packets take from your system to a remote host.


Example: traceroute google.com


This helps identify where packets are getting dropped. 


6. Check Firewall Settings 


Firewalls can block network connections. Check if any rules are affecting your connectivity.


Command: sudo iptables -L


If you find an issue, consider temporarily disabling the firewall to test the connection. 


26. What is the netstat Command? 


The netstat command is used in Linux to monitor network connections, routing tables, and statistics. It is important for network troubleshooting.


  • You can list all active connections with netstat. 


Command: netstat -a 


This shows both incoming and outgoing connections, helping you identify any ongoing network activity.


  • It lets you view services listening on specific ports. 


Command: netstat -l 


This helps you detect if required services are actively waiting for connections.


  • You can monitor network statistics. To get an overview of network performance, use: 


Command: netstat -s 


This displays statistics for different protocols, such as TCP, UDP, and ICMP.


  • This command can also show the system's routing table. 


Command:  netstat -r 


This helps verify that your default gateway and network routes are configured properly.


  • Display network interfaces statistics.  


Command: netstat -i 


You can see the status of each interface, including packets sent and received. 


27. How to Check the Default Run Level? 


The default run level in Linux defines what processes start at boot. Let’s get to know this in detail.


What is a Run Level?


Run levels control the mode your system operates in after booting. They range from 0 to 6, with each number representing a different state. For example, run level 0 is for shutting down, while run level 3 is multi-user mode without a GUI.


How to Check the Current Run Level? 


You can use the who -r command in the terminal. It will show the current run level of your system. Here's an example of the output: 


run-level 5  2024-09-10  18:45   last=S


In this case, the system is running at level 5, which includes a graphical interface.


Checking the Default Run Level


On most modern Linux systems, the default run level is set through systemd. You can check it by running the following command: 


systemctl get-default 


This command will display the default target, such as graphical.target for run level 5.


Changing the Default Run Level


To change the default run level, use the systemctl command. For example, to set the default to multi-user mode (run level 3), run: 


systemctl set-default multi-user.target 


After changing it, confirm with the systemctl get-default command.


Legacy Method (SysVinit Systems)


If you're working with an older system that uses SysVinit, the default run level is stored in the /etc/inittab file. You can check it with: 


cat /etc/inittab | grep initdefault 


This will show something like id:5:initdefault:, indicating run level 5 as the default.


With a clear understanding of run levels, you’ll be ready for more Linux interview questions related to system initialization. 


28. What is a Stateless Linux Server? Explain Its Features 


A stateless Linux server doesn’t store data locally. Instead, it relies on external sources to function. 


Definition of Stateless Servers 


A stateless server does not save client data between sessions. Each request is treated independently, meaning the server doesn’t remember previous interactions. This makes stateless servers highly scalable. 


Important Features of Stateless Linux Servers Include: 


  • No Local Storage: Stateless servers don’t retain user data on the machine itself. They rely on external databases or storage.

  • High Scalability: Because each request is independent, stateless servers can handle more traffic. You can add or remove servers easily based on demand.

  • Easy Recovery: If a stateless server crashes, it can be replaced with minimal disruption. Since no state is maintained, the replacement can pick up right away.

  • Automation-Friendly: Stateless servers are well-suited for automation. Tools like Ansible or Puppet can quickly provision new stateless servers. 


Use Cases for Stateless Servers 


Stateless servers are common in load balancing and microservices. For example, in cloud environments like AWS, you can use stateless servers for faster scaling. 


29. How to Administer Linux Servers? 


Administering Linux servers requires a mix of technical skills and attention to detail. Let’s get to its details: 


  • User Management: Managing users is a fundamental task. You’ll use commands like adduser, usermod, and passwd to create and modify user accounts. Make sure to assign proper permissions using chown and chmod.

  • File System Monitoring: Monitor the file system regularly to prevent issues. Use the df -h command to check disk space usage. You can also use du to monitor individual file sizes.

  • Package Management: Keep your Linux system updated with the latest software. On Debian-based systems, use apt-get update and apt-get upgrade. For Red Hat-based systems, use yum or dnf to install or update packages.

  • Network Configuration: Administering network settings is crucial. Use commands like ifconfig or ip to view and configure network interfaces. You can also use netstat to monitor network connections.

  • Backup and Recovery: Regular backups are essential. Tools like rsync and tar help you create backups easily. Store backups on external drives or remote servers.

  • System Security: Security should be a priority. Implement firewall rules using ufw or iptables. Regularly check for unauthorized access using logwatch and keep the system updated to address security vulnerabilities.


By conducting these tasks properly, you’ll confidently handle Linux server administration.  


30. How to Secure a Linux Server? 


Securing a Linux server is necessary to protect your data and services. Here’s how to do it: 


  • Update Your System Regularly: Always keep your Linux server up to date. Run commands like apt-get update and apt-get upgrade for Debian-based systems. Regular updates ensure that you have the latest security patches installed.

  • Use Strong Password Policies: Set strong password policies for all users. You can enforce this with the passwd command. Consider using tools like faillog to monitor failed login attempts and lock out suspicious users.

  • Disable Unnecessary Services: Disable any services you don’t need. You can use the systemctl or chkconfig commands to stop and disable these services. Fewer running services mean fewer entry points for attackers.

  • Implement a Firewall: Use a firewall to block unwanted traffic. Tools like ufw and iptables are common for configuring firewall rules. This adds a layer of protection by filtering incoming and outgoing traffic.

  • Use SSH Key Authentication: Replace password-based SSH access with SSH key authentication. Generate a key pair using the ssh-keygen command, and place the public key on the server. This makes it harder for attackers to gain access.

  • Monitor Logs Regularly: Regularly check system logs for any unusual activity. Use logwatch or journalctl to review logs and catch potential security threats early.

  • Install Anti-Malware Tools: Install tools like ClamAV to scan for malware. Regular scans help identify and remove malicious files that could harm your server.


With these security measures, you can significantly reduce the risk of attacks.


31. How to Optimize Linux System Performance? 


Optimizing your Linux system ensures it runs efficiently and handles tasks faster. Here are a few tips for the same: 


  1. Monitor System Resources: Use tools like top and htop to monitor CPU, memory, and disk usage. These tools help identify which processes are using the most resources. You can stop unnecessary processes with the kill command to free up CPU and memory.

  1. Optimize Disk I/O: Use the iotop tool to track disk input/output activity. If you notice high disk I/O, consider using faster SSDs or enabling file system features like journaling. This reduces disk access time and improves performance. 

  1. Manage Swap Usage: Swap memory can slow down your system. Monitor swap usage with the free -m command. If your system is using too much swap, consider adding more RAM to avoid excessive swapping.

  1. Adjust Process Priorities: You can change the priority of processes using the nice and renice commands. Lowering the priority of background tasks improves the performance of critical processes.

  1. Reduce Boot Time: To speed up boot time, disable unnecessary services. Use systemctl to identify and stop services that don't need to start at boot. This reduces the time it takes for the system to become fully operational.

  1. Tune Network Settings: Optimize network performance by tweaking kernel parameters. Use the sysctl command to adjust settings like net.ipv4.tcp_window_scaling for better network throughput.

  1. Regular System Updates: Keeping your system updated not only enhances security but also improves performance. Updates often come with performance improvements that can optimize your system’s overall efficiency.


This way,  your Linux system will run smoother and faster.  


32. What Are the Most Important Linux Commands? 


Here’s a list of the most essential Linux commands you should know: 


  1. ls – List Directory Contents: The ls command shows the contents of a directory. Use it to view files and subdirectories.  

Example: ls -l 

This command provides a detailed list, including file sizes and permissions.

  1. cd – Change Directory: You can use cd to move between directories. It’s one of the most basic commands for directory navigation. 

For example: cd /var/log 

This command moves you to the /var/log directory.

  1. cp – Copy Files and Directories: The cp command copies files or directories from one location to another. 

Example: cp file.txt /home/user/ 

This copies file.txt to the /home/user/ directory.

  1. rm – Remove Files and Directories: The rm command deletes files or directories. 

Example: rm -r directory/ 

This removes a directory and its contents.

  1. chmod – Change File Permissions: Use chmod to modify file or directory permissions. 

Example: chmod 755 file.txt 

This command gives the owner full access and others read/execute permissions.

  1. ps – Display Running Processes: The ps command shows running processes. Combine it with aux for detailed output: ps aux 

This displays all running processes, their CPU, and memory usage.

  1. top – Monitor System Resources: The top command is used to monitor real-time system resource usage, including CPU and memory. It helps you identify resource-heavy processes. 

  2. grep – Search Text in Files: The grep command searches for specific text within files. 


Example: grep "error" /var/log/syslog 


This command looks for the word “error” in the system log file.


Practicing these commands is crucial for effective Linux system management. 


33. How to Format a Disk in Linux? 


Here are the steps to format a disk in Linux. This process erases existing data, so ensure you backup important files:   


  1. Identify the Disk: First, you need to find the disk you want to format. 

Command: lsblk

This command lists all block devices. Identify your target disk by its size and name (e.g., /dev/sdX).

  1. Unmount the Disk: If the disk is mounted, unmount it before formatting. 

Command: sudo umount /dev/sdX1

Replace /dev/sdX1 with your disk's partition.

  1. Format the Disk: To format the disk, choose a filesystem type. Common types are ext4, xfs, and ntfs.

  • For ext4: sudo mkfs.ext4 /dev/sdX1

  • For xfs: sudo mkfs.xfs /dev/sdX1

  • For ntfs (requires additional tools): sudo mkfs.ntfs /dev/sdX1 

  1. Verify the Format: Check the new filesystem with the following command:

Command: sudo blkid /dev/sdX1

This shows details about the disk, confirming the filesystem type.

  1. Mount the Disk: Finally, mount the disk to a directory for use.

Command: sudo mount /dev/sdX1 /mnt/your_mount_point

Replace /mnt/your_mount_point with your desired mount directory.


34. What is RAID in Linux? 


RAID (Redundant Array of Independent Disks) is a technology used to manage data across multiple hard drives. It improves performance, reliability, or both, depending on the RAID level used. In linux interview questions, RAID is often discussed to assess your understanding of storage management. 


Types of RAID 


RAID comes in several levels, each serving a different purpose.


  • RAID 0: Focuses on performance. Data is split between drives but offers no redundancy.

  • RAID 1: Mirrors data between drives. If one drive fails, data is still safe on the other.

  • RAID 5: Combines both performance and redundancy. Data is striped, and parity is stored on different disks.


Software RAID vs. Hardware RAID 


In Linux, you can implement RAID in two ways:


  • Software RAID: Managed by the Linux kernel using mdadm. It offers flexibility and low cost.

  • Hardware RAID: Requires a dedicated controller. It offloads processing from the CPU.


Setting Up RAID in Linux 


To create a software RAID, you use the mdadm command.


Example: sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sda /dev/sdb /dev/sdc


This command creates a RAID 5 array using three disks. 


Benefits of RAID


RAID provides:


  • Increased performance for tasks requiring fast read/write speeds (RAID 0).

  • Data redundancy to prevent data loss in case of hardware failure (RAID 1, RAID 5).

  • Fault tolerance while maintaining good performance (RAID 5). 


35. What is LVM and Why is It Necessary? 


LVM (Logical Volume Manager) helps manage disk storage in a flexible and efficient way. It’s especially useful for growing systems and advanced storage needs. 


What is LVM? 


LVM lets you manage hard drives by grouping multiple physical disks into one logical volume. This logical volume can then be split, resized, or moved as needed. You aren’t limited by individual physical disks. 


Reasons to Use LVM:   


  • Flexible Disk Management: LVM allows you to resize volumes without unmounting or shutting down the system. For example, if you’re running out of space in your /home directory, you can easily extend the logical volume.

  • Snapshots for Backup: You can take snapshots of your data without interrupting the system. This is useful for quick backups and recovery.

  • Improved Disk Utilization: LVM combines multiple disks, letting you use them as a single storage pool. This increases efficiency, especially when you need to add more storage on the go. 


Example of LVM Usage 


Assume you have three 500GB disks. With LVM, you can combine them into a single 1.5TB logical volume. This logical volume can be used as a single partition, offering more storage flexibility. 


Advantages of LVM:  


  • Online resizing of volumes.

  • Disk migration without system downtime.

  • Efficient use of storage resources.


Understanding LVM helps you manage storage efficiently.  


36. What is the Difference Between Cron and Anacron? 


Cron and Anacron are both task schedulers in Linux, but they have different use cases. Understanding these differences will help you tackle Linux interview questions more effectively. 


Cron 


Cron is a time-based scheduler used to run tasks at fixed intervals. It works only when the system is running continuously. If your system is off when the task is scheduled, Cron won’t execute the task.  


Example of a Cron job: 0 5 * * * /path/to/script.sh


This runs the script every day at 5:00 AM. 


Anacron 


Anacron is designed for systems that aren’t running all the time. It ensures that tasks missed due to downtime will still run once the system is back online. Anacron uses days as the smallest unit of time, so it’s more suitable for less frequent tasks.


Example of an Anacron job in /etc/anacrontab


1 5 example-job /path/to/script.sh


This runs the script once a day, but only if the system was off during the scheduled time. 


Key Differences 



Cron is best for servers running 24/7, while Anacron suits machines with irregular uptime. Now that you understand their differences, let's move on to how you can automate backups on Linux servers.


37. What Are the Different Types of Modes Used in the Vi Editor? 


The Vi editor is a powerful text editor available on most Linux systems. It uses different modes for editing and navigating files. They are:   


  1. Normal Mode: In normal mode, you can move around and perform commands. It’s the default mode when you open Vi. Use this mode to delete, copy, or paste text. 

Example commands: 

  • dd – delete a line 

  • yy – copy a line 

  1. Insert Mode: Insert mode allows you to add text to the document. You can switch to this mode by pressing i. After entering your text, press Esc to return to normal mode.

  1. Visual Mode: Visual mode lets you select and manipulate text. Enter it by pressing v. You can select specific lines or blocks of text for copying, cutting, or formatting.

  1. Command-Line Mode: This mode allows you to save, quit, or run advanced commands. Enter it by typing : from normal mode. 

Examples include: 

  • :w – save the file 

  • :q – quit the editor

Each mode in Vi serves a specific purpose, making it versatile for editing tasks.  


 38. How to Exit From Vi Editor? 


Exiting from the Vi editor can seem tricky if you’re unfamiliar with it. Here’s how to do it better.


Exiting Without Saving Changes


  1. Press Esc to enter command mode.

  2. Type :q! and press Enter.

This command quits Vi without saving any changes made during the session.


Exiting and Saving Changes


  1. Press Esc to enter command mode.

  2. Type :wq and press Enter.

This command saves your changes and exits Vi.


Saving Changes and Continuing Editing


  1. Press Esc to enter command mode.

  2. Type :w and press Enter.

This command saves your changes but keeps you in the editor.


Quitting if No Changes Were Made


  1. Press Esc to enter command mode.

  2. Type :q and press Enter.

This command quits Vi if no changes were made since the last save.


These commands will make using Vi more straightforward.  


39. How to Delete Information From a File in Vi? 


Deleting information from a file in Vi requires a few simple steps.


  1. Open the File: Start by opening the file in Vi. Use the command: vi filename 

Replace filename with the name of your file. This command opens the file for editing.  

  1. Switch to Command Mode: Vi has two modes: Command and Insert. Press Esc to ensure you’re in Command mode. You can only delete text in Command mode.

  1. Deleting Single Characters: To delete a single character, place the cursor over the character and press x. This removes the character at the cursor position.

  1. Deleting Entire Lines: To delete an entire line, use dd. Move the cursor to the line you want to delete and press dd. The line is removed.

  1. Deleting Multiple Lines: To delete multiple lines, use d followed by a number and d. 

For example: 3dd   

This deletes the current line and the two lines below it.

  1. Deleting Text Until a Character: To delete text until a specific character, use d followed by t and the character. 

For example: dtx

This deletes text until the next occurrence of x on the line.

  1. Deleting Text from Cursor to End of Line: To delete text from the cursor to the end of the line, use d$. This removes all text from the cursor position to the end of the line. 

Editing files in Vi can be straightforward once you know the commands. 


40. What is the rsync Command and How to Use It for Synchronization? 


The rsync command or "remote sync." It synchronizes files and directories from one location to another, either locally or over a network. It only transfers the changes, making it fast and resource-efficient.


How to Use rsync Locally


To sync files between two directories on the same machine, use the following command: 


rsync -av /source/ /destination/ 


Here, -a preserves the file permissions, and -v shows detailed output.


Synchronizing Over a Network


You can use rsync to sync files between two machines over SSH: 


rsync -av -e ssh /source/ user@remote:/destination/ 


This command copies files from your local machine to a remote server using SSH for secure transfer.


Excluding Files


If you want to exclude specific files from the synchronization, use the --exclude option: 


rsync -av --exclude 'file.txt' /source/ /destination/ 


This skips file.txt during the sync.


Sync in Real-Time


To sync in real-time, use the --progress option to display the file transfer progress: 


rsync -av --progress /source/ /destination/ 


This shows you which files are being transferred and how much data is left.


With rsync, you can maintain efficient backups and ensure your data stays synchronized. 


41. What is a Latch? 


A latch in Linux is a synchronization mechanism. It ensures that only one process accesses shared data at a time. Latches are lightweight locks used to prevent race conditions in multi-threaded environments. Unlike full locks, latches are temporary and are usually released quickly, improving system performance.


For example, latches are commonly used in database systems to manage concurrency. They ensure that data consistency is maintained without significant performance overhead.


42. What is a Zombie Process?

 

A zombie process in Linux is a process that has completed execution but still exists in the process table. This happens when the parent process hasn’t read its exit status. The operating system keeps it in the table until the parent collects this status.


How Zombie Processes Occur? 


Zombie processes occur when a child process ends, but its parent process doesn’t call wait(). The child remains in the system's process table. You can check for zombie processes using the ps command: 


ps aux | grep Z 


The letter Z in the process status column indicates a zombie process.


How to Handle Zombie Processes? 


Most zombie processes are harmless, but too many can cause resource issues. You can manually force the parent process to collect the exit status by terminating it, often using the kill command: 


kill -9 <parent_process_id> 


This forces the parent process to end, which removes the zombie process. 


43. What Do You Mean by Shell Script?  


A shell script is a text file containing a series of commands for the Linux shell to execute. It helps automate repetitive tasks, saving you time and effort. Understanding shell scripts is important when answering Linux interview questions.


How Does a Shell Script Work?


A shell script works by executing each line of commands, just like you would in the terminal. It can include conditionals, loops, and variables, making it highly versatile.


Example of a Simple Shell Script


Here’s a simple shell script that prints “Hello, World!”: 


#!/bin/bash


echo "Hello, World!" 


The #!/bin/bash line tells the system to use the Bash shell to run the script.


Why Use Shell Scripts?


Shell scripts are widely used for automation. They can manage system backups, schedule tasks, or monitor system performance. You can also integrate shell scripts with other tools to create complex workflows.


44. How to Identify Which Shell You Are Using? 


Identifying the shell you're using is simple. The shell interprets your commands in Linux. 


You can check your shell by running the following command: 


echo $SHELL


This command will display the current shell, such as /bin/bash or /bin/zsh.


Another way is to use the ps command: 


ps -p $$


This will show the name of the active shell along with its process ID.


45. What Are the Challenges of Using Linux? 


While Linux is powerful, it comes with challenges that can impact users, especially beginners.


  • Steep Learning Curve: Linux requires you to learn many commands and concepts. This can be overwhelming for new users. Unlike GUI-based systems, you’ll need to use the terminal frequently.

  • Limited Software Compatibility: Some popular software doesn’t have Linux versions. You may need to use alternatives or workarounds like Wine, which can add complexity.

  • Hardware Compatibility Issues: Not all hardware works seamlessly with Linux. Some devices, especially older ones, may lack proper drivers. This can result in limited functionality or require manual configuration.

  • Less Commercial Support: Unlike Windows or macOS, Linux often lacks official support. You may need to rely on community forums or documentation, which might not always provide quick answers.

  • Fragmentation: There are many Linux distributions. Choosing the right one for your needs can be confusing. Each distro may have unique quirks, making the experience inconsistent.


Despite these challenges, learning and mastering Linux could be rewarding. 


46. What is the init Process in Linux? 


The init process is the first process that starts when you boot a Linux system. It has a Process ID (PID) of 1 and is responsible for starting all other processes. The init process initializes the system by setting up essential services, mounting file systems, and managing daemons.


The init process ensures that the system runs smoothly by managing processes according to the defined run levels. It remains active until the system shuts down. Different versions of Linux may use different init systems like System V or systemd.


For example, on a systemd-based system, the init process is replaced by systemd, which offers more advanced management features.  


47. What is the Difference Between Absolute and Relative Paths in Linux?  


Understanding the difference between absolute and relative paths is crucial for efficient file management in Linux. This is also useful when preparing for Linux interview questions.


Absolute Paths


An absolute path provides the complete address of a file or directory, starting from the root directory. It always begins with a forward slash (/). For example: 


/home/user/documents/file.txt 


This path points directly to the file, regardless of your current location in the directory structure.

 

Example: 
/etc/nginx/nginx.conf


This path points to the Nginx configuration file from the root directory. 


Relative Paths


A relative path describes the location of a file or directory relative to your current working directory. It does not start with a forward slash. For example: 


documents/file.txt 


If you are in the /home/user/ directory, this relative path will correctly locate file.txt inside the documents folder.


Example:   
../nginx/nginx.conf


If you are in /etc/, this relative path moves up one directory and then into nginx. 


48. How to Check the Status of a Service or daemon in Linux? 


Here’s how you can check the status of a service or daemon:


  • Using systemctl: For systems with systemd, use systemctl: 

systemctl status service_name 

Replace service_name with the name of the service. This command shows the service’s status, recent logs, and whether it is running.


  • Using service: On older systems with SysVinit, use: 

service service_name status 

This provides the status of the specified service.


  • Using ps: To check if a daemon is running, use ps: 

ps aux | grep daemon_name 

This lists processes related to the daemon. If it’s running, you’ll see it in the output.


  • Using netstat: For services listening on network ports, use: 

netstat -tuln | grep port_number 

Replace port_number with the port the service should be listening on. This confirms if the service is actively listening.


This way you can ensure your services and daemons are running correctly.  


49. What is the sed Command Used for in Linux? 


The sed command in Linux is a powerful stream editor. It’s used to perform basic text transformations on an input stream (a file or input from a pipeline).


Basic Use 


The primary use of sed is to edit files or text streams. You can use it to search, find, and replace text. For example: 


sed 's/old-text/new-text/' filename 


This command replaces old-text with new-text in filename.


Editing Files In-Place


You can modify files directly with the -i option. For example: 


sed -i 's/old-text/new-text/' filename 


This command changes old-text to new-text in the file without creating a new file.


Advanced Features


sed supports more complex operations like inserting or deleting lines. For instance: 


sed '2i\New line of text' filename 


This command inserts a new line after the second line of filename. 


50. What is Network Bonding in Linux? 


Network bonding in Linux combines multiple network interfaces into a single virtual interface. This improves redundancy and performance.


Its Benefits 


  • Increased Throughput: Bonding can combine bandwidth from multiple interfaces, boosting overall network performance.

  • Fault Tolerance: If one interface fails, traffic can continue through the remaining interfaces, ensuring network reliability.

  • Load Balancing: Distributes network traffic across multiple interfaces, balancing the load and improving efficiency.


Network bonding helps you handle complex Linux network setups. 


These are 50 most commonly asked Linux interview questions and their answers. However, we don’t need to tell you that this is a broad topic and there is a lot more you need to prepare for. We hope the above questions help you get started with your preparations. 


Grab One of the Best Jobs With Redrob 


Want to make your job hunt easier and more sophisticated? We can help. Redrob offers you one of the best job portals in India. Get access to a perfect place to showcase your skills and talents effectively.  


What Do You Get With Us? 

  • Authentic Interaction With Potential Employers 

  • AI-powered Profile Creation 

  • Direct Initial Chat With Job Providers 

  • Complete Data Security 


For more information, please click here


Become more visible and get hired at one of the top companies as soon as 20 days! SignUp Now

All-in-one sales and recruitment platform for startups

24/7 Support

Pune:

StartHub, 2nd Floor, Koregaon Park Rd, Pune, Maharashtra 411001

Noida:

i-Thum Tower - A, Office No-602 , Sector 62, Noida, Uttar Pradesh 201309

Bengaluru:

5th Block, BHIVE WORKSPACE, 19, 4th C Cross Rd, Koramangala Industrial Layout, Area, Bengaluru, Karnataka 560095

Explore more opportunities within our network. Use the dropdown menu to seamlessly navigate between our company websites and discover your requirement.

India

© 2023 McKinley Rice, Inc. All Rights Reserved.

Privacy Policy

All-in-one sales and recruitment platform for startups

24/7 Support

Pune:

StartHub, 2nd Floor, Koregaon Park Rd, Pune, Maharashtra 411001

Noida:

i-Thum Tower - A, Office No-602 , Sector 62, Noida, Uttar Pradesh 201309

Bengaluru:

5th Block, BHIVE WORKSPACE, 19, 4th C Cross Rd, Koramangala Industrial Layout, Area, Bengaluru, Karnataka 560095

Explore more opportunities within our network. Use the dropdown menu to seamlessly navigate between our company websites and discover your requirement.

India

© 2023 McKinley Rice, Inc. All Rights Reserved.

Privacy Policy

All-in-one sales and recruitment platform for startups

24/7 Support

Pune:

StartHub, 2nd Floor, Koregaon Park Rd, Pune, Maharashtra 411001

Noida:

i-Thum Tower - A, Office No-602 , Sector 62, Noida, Uttar Pradesh 201309

Bengaluru:

5th Block, BHIVE WORKSPACE, 19, 4th C Cross Rd, Koramangala Industrial Layout, Area, Bengaluru, Karnataka 560095

Explore more opportunities within our network. Use the dropdown menu to seamlessly navigate between our company websites and discover your requirement.

India

© 2023 McKinley Rice, Inc. All Rights Reserved.

Privacy Policy