dotlinux blog

10 Useful Random Linux Interview Questions and Answers

Linux is one of the most widely used operating systems in the world, especially in server environments, cloud computing, and open - source software development. When interviewing for a role that involves Linux knowledge, it's crucial to be well - prepared for a variety of questions. This blog presents 10 random yet highly useful Linux interview questions along with detailed answers to help you ace your next interview.

2026-06

Table of Contents#

  1. Question 1: What is the difference between hard links and soft links in Linux?
  2. Question 2: How do you check the disk usage in Linux?
  3. Question 3: What is the purpose of the /etc/fstab file?
  4. Question 4: Explain the concept of a process in Linux.
  5. Question 5: How can you find a specific word in a file in Linux?
  6. Question 6: What is the significance of the chmod command?
  7. Question 7: How do you schedule a task to run at a specific time in Linux?
  8. Question 8: What is the role of the init or systemd process?
  9. Question 9: How can you change the owner of a file in Linux?
  10. Question 10: What is the difference between the bash and sh shells?
  • Hard Links:
    • A hard link is a direct reference to the same inode (a data structure on a file system that stores information about a file) as the original file. In other words, multiple hard - linked files point to the exact same physical data on the disk.
    • You can create a hard link using the ln command without the -s option. For example, ln original_file hard_link.
    • Deleting the original file does not affect the hard link. As long as there is at least one hard link or the original file exists, the data will not be removed from the disk.
    • Hard links can only be created for files on the same file system. They cannot span different file systems.
  • Soft Links (Symbolic Links):
    • A soft link is an indirect reference to another file or directory. It contains the path to the original file or directory.
    • You create a soft link using the ln -s command. For example, ln -s original_file soft_link.
    • If the original file is deleted, the soft link becomes a broken link.
    • Soft links can span different file systems and can point to directories, which hard links cannot do for directories (in most cases).

Question 2: How do you check the disk usage in Linux?#

There are several commands available to check disk usage in Linux:

  • df (Disk Free):
    • This command is used to show the amount of disk space available on the file systems. The basic syntax is df.
    • To display the results in a more human - readable format (using units like KB, MB, GB), use df -h.
    • You can also specify a specific file system or mount point to get detailed information about that particular disk space. For example, df /home.
  • du (Disk Usage):
    • The du command is used to estimate file space usage. By default, it shows the disk usage of all files and sub - directories in the current directory.
    • To get a summary of the total disk usage of the current directory, use du -s.
    • For a human - readable output, use du -sh. You can also specify a particular directory to check its disk usage, like du -sh /var/log.

Question 3: What is the purpose of the /etc/fstab file?#

The /etc/fstab (File System Table) is a configuration file in Linux that contains information about the file systems that the system should mount at boot time and how they should be mounted. Each line in the /etc/fstab file typically has six fields:

  1. Device Specifier: This is the block device or disk partition that will be mounted. It can be a device node (e.g., /dev/sda1), a UUID (Universally Unique Identifier) of the partition, or a label.
  2. Mount Point: The directory where the file system will be mounted. For example, /home or /mnt.
  3. File System Type: The type of the file system, such as ext4, xfs, ntfs, etc.
  4. Mount Options: Options that control how the file system is mounted. Common options include defaults which sets the default mount options, ro (read - only), rw (read - write), etc.
  5. Dump: A flag used by the dump utility to determine whether the file system should be backed up. A value of 0 means no backup, 1 means it should be backed up.
  6. Fsck: This is the order in which the fsck (File System Check) utility should check the file system at boot time. A value of 0 means no check, values other than 0 indicate the order.

Question 4: Explain the concept of a process in Linux.#

In Linux, a process is an instance of a running program. Here are some key aspects:

  • Creation: A process is created by the operating system when a program is executed. The fork() system call is commonly used to create a new process (a child process) from an existing process (the parent process). After the fork(), the parent and child processes run independently.
  • Process ID (PID): Each process in Linux is assigned a unique Process ID (PID). The PID is used to identify and manage the process. You can use commands like ps to view the list of running processes and their PIDs. For example, ps -ef shows a detailed list of all processes.
  • States: A process can be in different states, such as running (actively using CPU resources), sleeping (waiting for an event like I/O), stopped (paused), or zombie (a terminated process whose entry in the process table is still there until the parent process reads its exit status).
  • Resource Management: Each process has its own set of resources, including memory space, open file descriptors, and CPU time. The operating system is responsible for allocating and managing these resources among processes.

Question 5: How can you find a specific word in a file in Linux?#

There are multiple ways to find a specific word in a file:

  • grep:
    • The grep (Global Regular Expression Print) command is one of the most commonly used tools for searching text in files. The basic syntax is grep "word" file.txt. This will print all the lines in the file.txt that contain the word "word".
    • You can use various options with grep. For example, -i for case - insensitive search (grep -i "word" file.txt), -r to search recursively in directories (grep -r "word" /path/to/directory).
  • ack:
    • ack is a tool designed for searching code. It is more user - friendly than grep in some cases, especially when dealing with large codebases. The syntax is similar to grep, e.g., ack "word" file_or_directory.
  • fgrep:
    • fgrep is a variant of grep that searches for fixed strings (it does not interpret the search pattern as a regular expression). The syntax is fgrep "word" file.txt.

Question 6: What is the significance of the chmod command?#

The chmod (Change Mode) command in Linux is used to change the permissions of files and directories. Permissions in Linux are divided into three categories: read (r), write (w), and execute (x), and they are set for three types of users: the owner of the file/directory, the group that the file/directory belongs to, and others.

  • Numeric Representation:
    • In the numeric mode, each permission is assigned a value: read is 4, write is 2, and execute is 1. You can combine these values to represent different permission sets. For example, chmod 755 file.txt gives the owner read, write, and execute permissions (4 + 2+ 1 = 7), the group read and execute permissions (4 + 1 = 5), and others also read and execute permissions (4 + 1 = 5).
  • Symbolic Representation:
    • The symbolic mode allows you to modify permissions in a more intuitive way. For example, chmod u+w file.txt adds write permission to the owner of the file. Here, u stands for user (owner), g for group, o for others, and + means add a permission, - means remove a permission.

Question 7: How do you schedule a task to run at a specific time in Linux?#

There are two main tools for scheduling tasks in Linux:

  • cron:
    • cron is a time - based job scheduler in Linux. You can create a cron job to execute a command or a script at a specific time, date, or interval.
    • Each user has their own cron table, which can be edited using the crontab -e command. The cron table has five fields for specifying the time and date (minute, hour, day of the month, month, day of the week) followed by the command to be executed. For example, to run a script backup.sh every day at 2:30 AM, you would add the following line to the cron table: 30 2 * * * /path/to/backup.sh.
  • at:
    • The at command is used to schedule a one - time task to run at a specific time. For example, to run a command ls -l at 3:00 PM today, you can use at 3:00 PM and then enter the command ls -l followed by Ctrl + D to confirm.

Question 8: What is the role of the init or systemd process?#

  • init:
    • In older Linux systems, init (Initialization) was the first process (PID 1) started by the kernel during the boot process. Its main role was to manage the system's boot sequence, start and stop system services, and handle the different runlevels of the system. Runlevels defined different states of the system, such as single - user mode, multi - user mode, etc.
  • systemd:
    • In modern Linux distributions, systemd has replaced init in many cases. systemd is a system and service manager that provides a more efficient and parallelized approach to system startup. It can manage services asynchronously, reducing the boot time. systemd also introduces the concept of units (such as service units, socket units, etc.) to manage system resources and services more effectively. For example, you can use systemctl commands to start, stop, enable, or disable services.

Question 9: How can you change the owner of a file in Linux?#

You can use the chown (Change Owner) command to change the owner of a file or directory in Linux.

  • Changing the Owner:
    • The basic syntax is chown new_owner file_or_directory. For example, chown john file.txt changes the owner of file.txt to the user john.
  • Changing Both Owner and Group:
    • You can also change both the owner and the group of a file or directory at the same time. The syntax is chown new_owner:new_group file_or_directory. For example, chown john:developers file.txt changes the owner to john and the group to developers.
  • Recursive Change:
    • If you want to change the owner and/or group of a directory and all its sub - directories and files recursively, use the -R option. For example, chown -R john:developers /home/john_projects.

Question 10: What is the difference between the bash and sh shells?#

  • sh:
    • sh is the standard Unix shell. It is a simple shell that follows the POSIX shell standard. It provides basic shell functionality such as command execution, variable assignment, and basic control structures.
    • In many Linux distributions, sh is actually a symbolic link to another shell. For example, in some systems, it may point to dash, which is a lightweight shell designed for speed and compliance with the POSIX standard.
  • bash:
    • bash (Bourne - Again SHell) is an enhanced version of the sh shell. It is the most commonly used shell in Linux systems.
    • bash has many additional features compared to sh, such as command history, job control, programmable completion, and more advanced scripting capabilities. It also provides a more user - friendly environment for interactive use.

Conclusion#

Preparing for a Linux interview requires a solid understanding of various Linux concepts and commands. By familiarizing yourself with these 10 random yet important interview questions and their answers, you can increase your chances of success in your next Linux - related interview.

References#

  • "The Linux Documentation Project" - A comprehensive resource for Linux documentation.
  • "Linux in a Nutshell" by Ellen Siever, Stephen Figgins, Robert Love, and Arnold Robbins. This book provides in - depth knowledge of Linux commands and concepts.
  • Online Linux communities such as Stack Overflow and Reddit's r/linux for real - world examples and discussions.