Question library

Linux interview questions and answers

45 Linux interview questions with answers: 10 junior, 15 mid-level and 20 senior. Junior answers are free to read.

Junior Mid Senior Updated How these answers are created

* View counts were reset on 18 October 2026, when Interviewplus moved to interviewplus.app. Votes were not affected.

Answer

The terms terminal, shell, and command line are often used interchangeably but refer to different components in a Linux environment.

A terminal is a physical or virtual interface that allows users to interact with the system. It can be a hardware device, like an old-school terminal connected to a mainframe, or a software application like GNOME Terminal or xterm. Essentially, it acts as a window where you can enter commands.

A shell is a program that interprets and executes the commands entered by the user. In Linux, the most common shell is Bash (Bourne Again SHell), but there are others like Zsh, Ksh, and Fish. The shell processes the command line input entered in the terminal, interprets it, and then communicates with the system to perform the requested actions, such as running scripts or programs.

The command line specifically refers to the input area where you type your commands within the terminal. It’s the text-based interface where you can execute commands by typing them and pressing Enter. For example, if you type ls -l at the command line and press Enter, the shell interprets this command and returns a list of files in the current directory in long format.

In summary, the terminal is your environment for interaction, the shell is the command interpreter, and the command line is where you enter your commands.

Answer

To check the current working directory in Linux, you can use the pwd command, which stands for "print working directory." When you execute this command in the terminal, it displays the full path of the directory you are currently in.

For example, if you type:

pwd

The output might look something like this:

/home/user/documents

This indicates that your current working directory is /home/user/documents.

Additionally, if you're using a shell script or need to incorporate the current directory into variable assignments, you can also use the pwd command within a script or command line. For instance:

current_dir=$(pwd)
echo "You are currently in: $current_dir"

This will store the current working directory in the variable current_dir and then print it. This command is a fundamental part of navigating and managing files in Linux, as knowing your current location in the file system is crucial for file manipulation and organization.

Answer

The chmod command in Linux is used to change the file system permissions of files and directories. It allows users to define who can read, write, or execute a file, thus controlling access and security. The command can set permissions for three types of users: the owner of the file, the group associated with the file, and others (everyone else).

Permissions can be represented in either symbolic or numeric form. In symbolic notation, you use letters to indicate the user types (u for user, g for group, o for others, and a for all) and permissions (r for read, w for write, x for execute).

For example:
- To give the owner execute permission on a file named script.sh, you would use:

chmod u+x script.sh

In numeric notation, permissions are represented by three digits, with each digit corresponding to the owner's, group’s, and others’ permissions. Each permission is represented by a numerical value: read (4), write (2), and execute (1). These values are added together to represent combined permissions.

For example:
- To set read and write permissions for the owner, read for the group, and no permissions for others on a file named data.txt, you would use:

chmod 640 data.txt

This versatility allows users to maintain strict control over their files and directories in Linux.

Answer

The root directory in the Linux filesystem, denoted by a single forward slash /, is the topmost directory in the hierarchy and serves as the starting point for the entire filesystem structure. Its significance can be understood in several key aspects:

1. Hierarchy Structure: The root directory is the foundation of the Linux filesystem tree, from which all other directories branch off. It employs a hierarchical structure that organizes files and directories, making it easier to manage and navigate the system. For example, common subdirectories like /bin, /etc, /home, /var, and /usr all exist under the root directory.

2. File Organization: The root directory allows for organized storage of files and applications. Each important component of the system is typically housed in its respective subdirectory. For instance:
- /bin contains essential binary executables for system booting and commands.
- /etc is used for system configuration files.
- /home stores user-specific data and personal directories.

3. Access Control: The root directory plays a critical role in access control and permissions. Only users with root privileges can modify or access certain files and directories, ensuring system security. This distinction is crucial for maintaining the integrity of system files while allowing regular users to operate their personal files within the /home directory.

4. System Boot and Recovery: The root directory is paramount for system initialization. During the boot process, the operating system looks for essential files within this directory to launch services and manage filesystems. In recovery scenarios, access to the root directory is needed to perform system repairs or restore files.

5. Unified Structure: The root directory contributes to the unification of different filesystems. For instance, it can link to various mounted filesystems (like CD-ROMs or USB drives) to make them accessible at specific points in the directory structure (e.g., /mnt or /media).

In summary, the root directory is fundamental to the organization, accessibility, security, and booting of a Linux system, forming the backbone of the Linux filesystem architecture.

Answer

To list all files and directories, including hidden ones, in the terminal, you can use the ls command with the -a option. The command would be:

ls -a

The -a flag stands for "all" and it shows all files in the directory, including those that are hidden (which typically start with a dot .).

For example, if you want to list all files and directories in your home directory, you would navigate to that directory using cd and then run:

cd ~
ls -a

This will display a list that includes standard files and directories, as well as hidden ones like .bashrc, .git, and .profile.

If you would like a more detailed list with additional information such as file permissions, ownership, and size, you can use the -l option along with -a:

ls -la

This combines the long list format with the visibility of all files, providing a comprehensive view of the contents in the directory.

Answer

A symbolic link, often referred to as a symlink, is a type of file in Linux that acts as a pointer or shortcut to another file or directory. Unlike a hard link, which points directly to the inode of a file on disk, a symbolic link contains a path to the target file or directory, allowing it to refer to files that are located on different file systems.

To create a symbolic link in Linux, you use the ln command with the -s option. The basic syntax is:

ln -s [target_file_or_directory] [link_name]

For example, if you have a directory named /var/www/html and you want to create a symbolic link to it in your home directory, you would run the following command:

ln -s /var/www/html ~/my_html_link

After executing this command, you'll find a new symbolic link named my_html_link in your home directory. When accessing my_html_link, it will redirect you to the original /var/www/html directory.

A clarification: If the target file or directory is moved or deleted, the symbolic link will become "broken," meaning it will point to a non-existent location. You can check whether a symlink is broken by using the ls -l command, which will indicate the target of the link.

Answer

To find and display the contents of a file in the terminal, you can use several commands, depending on your needs.

1. Using cat: The simplest way to display the contents of a file is with the cat command. For example:

cat filename.txt

This will output the entire content of filename.txt to the terminal.

2. Using less: If the file is large, you may want to use less, which allows for easy navigation through the content:

less filename.txt

You can scroll through the file using the arrow keys, and press q to exit.

3. Using more: Similar to less, more also allows you to view large files one screen at a time:

more filename.txt

You can press the space bar to go to the next page and q to quit.

4. Using head and tail: If you're only interested in the beginning or end of the file, you can use head or tail. For example, to view the first 10 lines:

head filename.txt

And to view the last 10 lines:

tail filename.txt

5. Searching within a file: If you want to find a specific string in the file before displaying it, you could use grep:

grep 'search_term' filename.txt

In summary, the method you choose depends on the size of the file, whether you want to see it all at once, or if you prefer to navigate through it. Each command provides a convenient way to access file content directly from the terminal.

Answer

To view the permissions of a file in Linux, you can use the ls -l command in the terminal. This command lists files in a directory in a long format, showing detailed information about each file, including its permissions.

The output of ls -l will look something like this:

-rw-r--r-- 1 user group 12345 Oct 1 12:00 filename.txt

In this output:
- The first character indicates the file type (- for a regular file, d for a directory, l for a symbolic link).
- The next nine characters are divided into three groups of three. Each group represents the permissions for the owner, the group, and others, respectively:
- The first three characters (e.g., rw-) indicate the owner's permissions: r for read, w for write, and x for execute. A - indicates that permission is not granted.
- The second group of three characters (e.g., r--) shows the permissions for the group.
- The last group (e.g., r--) shows the permissions for others.

For example, in the output above:
- The owner has read and write permissions but not execute (rw-).
- The group has read permission only (r--).
- Others also have read permission only (r--).

If you want to check the permissions of a specific file, you can use ls -l filename.txt, replacing filename.txt with the name of the file you wish to inspect. Additionally, using the stat filename.txt command can provide even more detailed file information, including access permissions, modification date, and file size.

This method allows developers to assess who can read, write, or execute a file, which is vital for maintaining proper security and access controls in a Linux environment.

Answer

A package manager is a software tool that automates the process of installing, upgrading, configuring, and removing software packages in a Linux operating system. It simplifies the management of software dependencies by handling the packages' requirements and ensuring that all necessary components are installed correctly.

A well-known example of a package manager in Linux is APT, which stands for Advanced Package Tool. APT is primarily used in Debian-based distributions, such as Ubuntu. With APT, users can easily install software from the command line using commands like apt install package_name or update their system with apt update and apt upgrade. APT resolves dependencies automatically, making software management efficient and user-friendly.

In addition to APT, there are other package managers in Linux, such as YUM (Yellowdog Updater Modified) used in Red Hat-based distributions, and Pacman used in Arch Linux. Each of these tools serves a similar purpose but is tailored to the management of software packages specific to their respective distributions.

Answer

To create a new directory in Linux using the command line, you can use the mkdir command, which stands for "make directory." The basic syntax for the command is:

mkdir [directory_name]

For example, if you want to create a directory named "projects," you would type:

mkdir projects

If you need to create a directory with spaces in its name, you should enclose the name in quotes, like this:

mkdir "my projects"

Additionally, if you want to create nested directories in one command, you can use the -p option. This option allows you to create parent directories as needed. For instance, to create a directory structure dir1/dir2/dir3, you would use:

mkdir -p dir1/dir2/dir3

This command will create dir1, dir2 within dir1, and dir3 within dir2, all in one go.

Answer preview

To check which processes are currently running on a Linux system, I would typically use the `ps` command. This command provides a snapshot of the current processes running on the system. The most common usage is `ps aux`, which displays a detailed list of all running processes, including user information, CPU and…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

The `grep` command stands for "Global Regular Expression Print." It is a powerful tool used in Linux for searching plain-text data for lines that match a regular expression. This command is commonly used to filter output or search files for specific patterns. ### Basic Syntax The syntax of the `grep` command is…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

Hard links and soft links (also known as symbolic links) are two different methods for linking files in Linux, and they each have unique characteristics. Hard Links: 1. File System Level: Hard links are essentially additional directory entries for an existing file; they point directly to the inode of the original…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To automate tasks using cron jobs in Linux, you first need to understand how the cron system works. Cron is a time-based job scheduler that allows users to run scripts or commands at specified intervals, such as minute, hour, day, week, or month. 1. Editing the Crontab: Each user has their own crontab file where they…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

The `sudo` command stands for "superuser do" and allows a permitted user to execute a command as the superuser or another user, as specified by the security policy in the `/etc/sudoers` file. It is typically used to perform administrative tasks without needing to switch to the root user entirely. For example, a user…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

Managing software dependencies in a Linux environment can be approached in several ways, depending on the specific use case and the complexity of the project. Here are some key strategies I utilize: 1. Package Managers: I primarily use package managers like `apt` for Debian-based systems (e.g., Ubuntu), `yum` or `dnf`…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

The `/etc/passwd` file in Linux serves as a crucial database that stores essential information about all user accounts on the system. Each line in this file corresponds to an individual user and contains several fields separated by colons. These fields typically include the username, password placeholder (usually an…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To check system resource usage and performance metrics in Linux, you can use a variety of command-line tools that provide insights into different aspects of system performance. Here are some common methods: 1. Top Command: The `top` command is one of the most useful tools for real-time monitoring of system processes…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To troubleshoot a failing service in a Linux environment, I would follow a systematic approach: 1. Check the Service Status: First, I would check the status of the service using `systemctl status `. This command provides information about whether the service is active, inactive, or failed, along with its recent logs…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To secure a Linux server, I would take the following steps: 1. Update and Patch: Regularly update the OS and installed packages using tools like `apt`, `yum`, or `dnf` to ensure all security patches are applied. 2. User Management: Limit the number of users with administrative privileges. Use the principle of least…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To find out the available disk space in a Linux system, you can use the `df` (disk free) command, which reports the amount of disk space used and available on filesystem mounts. The most common usage is: The `-h` option stands for "human-readable," and it displays the sizes in a format that is easier to understand…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

The `file` command in Linux is a utility that determines and displays the type of a specified file. It analyzes the contents of the file rather than relying solely on the file extension to ascertain its type. This is particularly useful in a Linux environment, where file extensions are not strictly enforced, and…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

A shell script is a text file that contains a sequence of commands for a Unix-based operating system's shell to execute. It is essentially a way to automate tasks, allowing users to combine several commands to perform complex operations efficiently. Shell scripts are written in shell programming languages, such as…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

Linux kernel modules are pieces of code that can be loaded into the kernel on demand, extending its functionality without the need to reboot the system. They allow developers to add support for new hardware, filesystems, or system calls dynamically. Modules can be inserted or removed from the kernel at runtime, which…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

One challenging problem I faced in a Linux environment was during a deployment of a web application on a remote server. We were using a combination of Nginx and PHP-FPM, and after deploying the application, we encountered intermittent 502 Bad Gateway errors. Initially, I checked the Nginx error logs, which indicated…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To diagnose and resolve a kernel panic in a Linux system, I would follow a systematic approach using several tools and techniques. First, I would check the logs to identify potential causes. The command `journalctl -k` allows me to view kernel logs. I would look for any messages leading up to the panic that might…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To configure and optimize a Linux system for high availability (HA), it's essential to ensure that your system can prevent downtime and provide continuous access to services. The following steps outline the best practices and technologies involved: 1. Redundant Hardware: Use multiple servers (nodes) in a HA cluster to…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To implement a centralized logging solution in a multi-server environment, I would follow these steps: 1. Log Collection Tool Selection: I would choose a log collection tool like Fluentd or Filebeat. These tools efficiently collect log data from various sources and forward it to a centralized location. Fluentd is…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

The SUID (Set User ID) and SGID (Set Group ID) bits are special permissions in Linux that allow users to execute files with the permissions of the file owner or group, respectively. While they can be useful for granting necessary privileges without changing the ownership of a program, they also pose significant…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

Certainly! Systemd, Upstart, and SysVinit are all service management systems used in Linux, but they differ significantly in design, features, and operational methodologies. SysVinit is the traditional init system inherited from UNIX systems. It uses a series of scripts located in `/etc/init.d/` and associated…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To perform a forensic analysis on a compromised Linux server, I would follow a structured methodology, which I outline below: 1. Preparation: Before initiating any forensic investigation, I would ensure that I have the necessary tools and resources available. This includes creating a forensic toolkit that contains…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

The Linux kernel architecture follows a monolithic design, which means it comprises a single large block of code running in a single address space. This architecture allows the kernel to manage system resources effectively and provide high performance when interacting with hardware components. The Linux kernel is…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To set up a firewall in Linux using `iptables`, you'll first want to understand the basic structure of `iptables`, which operates using chains of rules that process packets. The primary chains are INPUT, FORWARD, and OUTPUT. Each chain can hold rules to allow or deny traffic based on various criteria such as…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

Cgroups, or control groups, and namespaces are two fundamental features in the Linux kernel that facilitate containerization, enabling the creation of lightweight, isolated environments. Cgroups allow the allocation and limitation of resources such as CPU, memory, disk I/O, and network bandwidth for a group of…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To create and manage a Logical Volume Management (LVM) setup in Linux, the process involves several steps: 1. Prerequisites: Ensure that LVM is installed on your system. You can check this with the command `lsblk` or `lvm version`. If it isn’t installed, you can typically install it using your package manager (e.g…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

A monolithic kernel and a microkernel represent two distinct approaches to operating system architecture. Monolithic Kernel: In a monolithic kernel architecture, the entire operating system, including core services such as device drivers, file system management, and system calls, runs in a single address space in…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To troubleshoot network issues in a Linux environment, I would follow a systematic approach using various tools and commands. Here’s a step-by-step process: 1. Check Network Interface Status: I would begin by checking the status of the network interfaces using the command: This shows the list of all network interfaces…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

The `chroot` command in Linux changes the apparent root directory for the current running process and its children. This is done by specifying a new directory as the target root, effectively isolating the process from the rest of the filesystem. Once a process is executed in a chrooted environment, it cannot access…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

Certainly! Managing and configuring SELinux or AppArmor involves understanding their architecture, policies, and how they interact with the Linux kernel. SELinux: 1. Architecture: SELinux is built on a mandatory access control (MAC) mechanism that enforces the security policies. Key components include: - Policy Types…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To conduct a system performance analysis on a Linux server, I would follow a systematic approach that includes identifying the key metrics, using appropriate tools, and ultimately interpreting the data to identify performance issues. 1. Identify Key Metrics: The critical areas I would focus on include: - CPU Usage: To…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

The boot process of a Linux system involves several key components: BIOS/UEFI, bootloader, kernel, and init system. 1. BIOS/UEFI: The boot process begins when the computer is powered on. The BIOS (Basic Input/Output System) or UEFI (Unified Extensible Firmware Interface) performs Power-On Self-Test (POST) to check…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

To implement encryption for data at rest on a Linux server, I would follow a structured approach using established tools and best practices. Firstly, I would identify what data needs to be encrypted. This could include sensitive files, databases, or entire disk partitions. For encrypting files and directories, I would…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

NFS (Network File System) and SMB/CIFS (Server Message Block/Common Internet File System) are both protocols used for sharing files over a network, but they have different design philosophies and use cases. NFS is primarily designed for Unix/Linux environments and is integrated natively into these systems. It allows…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

Certainly! Setting up an effective backup and disaster recovery plan on a Linux server involves several key steps and strategies: 1. Assessment and Planning: First, assess the data that needs to be backed up. This includes databases, configuration files, user data, and any custom applications. Determine the Recovery…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

Answer preview

In a previous role, I was working on a project that required deploying a web application on a Linux server. Midway through the project, we decided to use Docker to containerize the application for better scalability and management. I had limited experience with Docker, and the deadline was tight. To tackle this, I…

Sign in to view this answer

Mid and senior level answers are included in every paid plan. Sign in to choose a plan, or browse the junior level answers for free.

More practice

Go further with Linux

Linux code challenges

10 challenges with answers

Behavioral Questions

10 questions with answers

Cultural Fit Questions

10 questions with answers

Competency-Based Questions

10 questions with answers

Motivational Questions

10 questions with answers

Communication Skills Questions

10 questions with answers

Scenario-Based Questions

10 questions with answers

Problem-Solving and Analytical Questions

10 questions with answers

Ethical and Integrity Questions

10 questions with answers

Industry-Specific Questions

10 questions with answers

Leadership and Management Questions

10 questions with answers

Personal Questions

10 questions with answers

About this topic

Linux interview questions and answers

This page lists 45 Linux interview questions with answers, ordered from junior to senior level. Commonly asked questions include "What is the difference between a terminal, shell, and command line in Linux?", "How can you check the current working directory in Linux?" and "What is the purpose of the `chmod` command in Linux?".

Other frequently asked questions include "How do you list all files and directories, including hidden ones, in the terminal?", "What is a symbolic link in Linux, and how do you create one?" and "How would you check which processes are currently running on a Linux system?". Review each answer and consider how you would adapt it to your own experience.

Practise Linux in a mock interview

Answer questions one at a time and receive a score with written feedback on each answer.

Start a mock interview

Reviews and comments