Top 50 Linux Interview Questions and Answers

  • By Gandhar Bodas
  • February 24, 2025
  • Linux
Top 50 Linux Interview Questions and Answers

Top 50 Linux Interview Questions and Answers

Discover the Top 50 Linux Interview Questions and Answers with expert training, hands-on labs, and certification. Upgrade your Linux skills and boost your career today!

 

Q1: What is Linux and why is it popular?

A: Linux is an open-source operating system that is widely used on many devices such as computers, smartphones, and servers. It is based on the Unix operating system and is known for its stability, security, and flexibility. Linux is popular because it’s free, open-source, and highly customizable.

 

Q2: Who is the creator of Linux?

A: Linux was created by Linus Torvalds in 1991. He developed the first version of Linux as a hobby while studying at the University of Helsinki in Finland.

 

Q3: Can you explain the history of Linux from its creation to now?

A: Linux was started by Linus Torvalds as a personal project. Initially, he wanted to create a free alternative to the MINIX operating system. Linux became open-source, meaning anyone could modify and share it. Over the years, it grew in popularity, and many different distributions (like Ubuntu, Red Hat, and Debian) were created. Today, it powers millions of devices around the world.

 

Q4: How is Linux different from Unix?

A: Linux and Unix are both operating systems with similar structures, but Linux is open-source and free, while Unix is proprietary and usually more expensive. Linux was designed to be a free and open alternative to Unix, and it is more flexible and customizable.

 

Q5: What is the most important part of the Linux operating system?

A: The core of the Linux operating system is called the “Linux Kernel.” The kernel manages hardware resources, such as memory and processing power, and allows software to communicate with the hardware.

 

Q6: Can you explain what the Linux Kernel does?

A: The Linux Kernel is the central part of the Linux operating system. It is responsible for managing hardware resources, like CPU, memory, and disk drives. It also controls the interactions between the software and the hardware.

 

Q7: What is CLI in Linux?

A: CLI stands for Command-Line Interface. It allows users to interact with the computer by typing text-based commands instead of using graphical interfaces. It’s commonly used for system administration and troubleshooting in Linux.

 

Q8: How can you install Linux on VMware Workstation?

A: To install Linux in VMware Workstation, first, download the Linux ISO file. Then, open VMware Workstation, create a new virtual machine, select the Linux ISO, and follow the installation steps (partitioning, time zone, etc.) until installation is complete.

 

Q9: How does the Linux boot process work?

A: The Linux boot process involves several stages:

  1. BIOS/UEFI loads the bootloader (GRUB).
  2. GRUB loads the Linux Kernel.
  3. The Kernel initializes hardware and mounts the root filesystem.
  4. The init process starts with system services and user processes.

 

Q10: How do you navigate Linux using the terminal?

A: To navigate in Linux, you can use basic commands:

  • pwd (Print Working Directory) to see the current directory.
  • ls to list files in a directory.
  • cd to change directories.
  • mkdir to create a directory.

 

Q11: What are the basic commands in Linux?

A: Some basic Linux commands include:

  • ls: List files in a directory.
  • cd: Change directories.
  • touch: Create an empty file.
  • cp: Copy files.
  • mv: Move or rename files.
  • rm: Remove files.
  • cat: Display the contents of a file.

 

Q12: What is the purpose of the find and grep commands?

A:

  • The find command helps you search for files and directories by name, size, type, etc.
  • The grep command is used to search for specific patterns inside files. For example, grep “error” logfile.txt will find all occurrences of “error” in logfile.txt.

 

Q13: How do you get help in Red Hat Enterprise Linux?

A: You can use the man command to access the manual pages of Linux commands. For example, man ls will show you the manual for the ls command, explaining its options and usage.

 

Q14: How can you create and edit text files in Linux?

A: You can create and edit text files using editors like nano, vim, or gedit. For example:

  • To create or edit a file: nano filename.txt.
  • To view a file: cat filename.txt.

 

Q15: How do you manage users and groups in Linux?

A: To manage users:

  • useradd username to add a new user.
  • passwd username to set or change the user’s password. To manage groups:
  • groupadd groupname to create a new group.
  • usermod -aG groupname username to add a user to a group.

 

Q16: How can you control access to files in Linux?

A: You can control file access using file permissions. Use the chmod command to change permissions. For example:

  • chmod 755 filename gives full permissions to the owner and read/execute permissions to others.

 

Q17: What are ACLs, and how are they used?

A: ACLs (Access Control Lists) allow for more fine-grained control of file permissions. You can set ACLs using the setfacl command. For example, setfacl -m u:username:r– filename grants read-only access to a user.

 

Q18: How do you monitor and manage processes in Linux?

A: Use the ps command to view running processes and top for a real-time view. You can stop processes using kill followed by the process ID.

 

Q19: What are the Process states in Linux?

A: Five process states in Linux. They are

  • New/ Ready: A new process is created and ready to run.
  • Running: The process is being executed.
  • Blocked/ Wait: The process is waiting for input from the user. 
  • Terminated/ Completed: The process completed the execution or terminated by the operating system. 
  • Zombie: The process is deleted, but still the information regarding the process exists in the process table.

 

Q20: Explain Process Management System Calls in Linux.

A: The process management system calls in Linux:

  • fork(): Used to create a new process.
  • exec(): Execute new process.
  • wait(): wait until process execution.
  • exit(): exit from the process.

System calls to get the Process id :

  • getpid(): to find the unique process id. 
  • getppid(): to find the unique parent process id.

 

Q21: How can you analyze logs in Linux?

A: Logs in Linux are usually stored in /var/log. You can view them with commands like cat, tail, or less. For example, tail -f /var/log/messages show real-time log updates.

 

Q22: How do you schedule tasks in Linux?

A: You can schedule tasks using cron. Use crontab -e to edit cron jobs. For example, 0 5 * * * /path/to/script.sh will run a script every day at 5 AM.

 

Q23: How can you improve the performance of a Linux system?

A: You can tune performance by managing system resources, such as memory and CPU usage, using tools like top, htop, and adjusting sysctl settings.

 

Q24: How do you manage networking in Linux?

A: You can configure networking settings using commands like ifconfig, ip, and nmcli. For example, ifconfig shows the network interfaces and their IP addresses.

 

Q25: How do you secure SSH in Linux?

A: To secure SSH, you can:

    • Change the default SSH port.
    • Disable root login by modifying the /etc/ssh/sshd_config file.
  • Use key-based authentication instead of passwords.

 

Q26: How do you archive and transfer files in Linux?

A: Use commands like tar to create archives and scp to transfer files. For example:

  • tar -cvf archive.tar /path/to/folder creates an archive.
  • scp file username@remote:/path/to/destination transfers a file.

 

Q27: What is SELinux, and how do you manage it?

A: SELinux (Security-Enhanced Linux) is a security module that provides mandatory access controls. You can manage SELinux with the getenforce and setenforce commands, which control its enforcement mode.

 

Q28: How do you manage network security in Linux?

A: You can manage firewall settings using firewalld or iptables. For example, firewall-cmd –add-port=80/tcp opens port 80 for HTTP traffic.

 

Q29: How do you manage storage in Linux?

A: Use the df command to view disk usage and fdisk or parted to partition disks. The mount command is used to mount storage devices.

 

Q30: How do you use LVM in Linux?

A: LVM allows you to manage disk volumes. Use commands like lvcreate to create logical volumes and vgextend to extend volume groups.

 

Q31: How do you run containers in Linux?

A: You can run containers using Docker. First, install Docker, then use commands like docker run to start containers.

 

Q32: How do you access network-attached storage (NAS) in Linux?

A: You can access NAS using protocols like NFS or SMB. Use the mount command to connect to the network share.

 

Q33: How do you install and use MariaDB in Linux?

A: Install MariaDB using yum install mariadb-server, then start the service with systemctl start mariadb. You can interact with it using the mysql command.

 

Q34: How do you configure a Samba server in Linux?

A: To configure a Samba server, install it using yum install samba, edit the /etc/samba/smb.conf file to define shared directories, and restart the Samba service.

 

Q35: How can you write simple shell scripts in Linux?

A: To write a shell script, create a file with the .sh extension, use a text editor to add commands, and make the file executable with chmod +x script.sh. Then, run the script using ./script.sh.

 

Q36: How do you use systemctl to manage system services in Linux?

A: systemctl is used to start, stop, restart, and enable services in Linux. For example:

  • systemctl start apache2 starts the Apache web server.
  • systemctl stop apache2 stops it.
  • systemctl restart apache2 restarts the service.
  • systemctl enable apache2 makes sure the Apache service starts automatically on boot.

 

Q37: How do you check the available disk space on a Linux system?

A: You can use the df command to check disk space usage. For example:

  • df -h shows disk space in human-readable format (GB, MB). This command lists all mounted filesystems and their space usage.

 

Q38: What does the /etc/fstab file do in Linux?

A: The /etc/fstab file is used to define how disk partitions and storage devices are mounted into the filesystem. It contains information like the device name, mount point, filesystem type, and mount options.

 

Q39: How do you create a compressed file in Linux using tar?

A: You can use the tar command to create compressed archives. For example:

  • tar -czvf archive.tar.gz /path/to/directory creates a .tar.gz compressed archive.
  • tar -xzvf archive.tar.gz extracts a .tar.gz file.

 

Q40: How can you find large files on a Linux system?

A: You can use the find command with the -size option to search for large files. For example:

  • find / -size +100M finds files larger than 100 MB.
  • find /home -size +1G finds files larger than 1 GB in the /home directory.

 

Q41: What does the uptime command show in Linux?

A: The uptime command shows how long the system has been running since the last reboot, along with the number of users logged in and the system’s load average over the last 1, 5, and 15 minutes.

 

Q42: How do you check the memory usage on a Linux system?

A: You can use the free command to check memory usage:

  • free -h gives a summary of used and available memory in a human-readable format. You can also use top to get real-time memory usage details.

 

Q43: How do you change the owner of a file in Linux?

A: Use the chown command to change the file owner. For example:

  • chown username:groupname filename changes the file owner and group.

 

Q44: What is the difference between sudo and su in Linux?

A:

  • sudo allows a user to run commands with superuser privileges temporarily without switching to the root user.
  • su (substitute user) switches to the root user or another user, and you need the root password to use it.

 

Q45: What are the default ports used for SMTP, DNS, FTP, DHCP, and SSH

A: Details mentioned below

Services Port No
SMTP 25
DNS 53
FTP 20 (Data Transfer) ,21 (Connections Established)
DHCP 68 (DHCP), 67 (DHCP Server)
SSH 22

 

Q46: How can you check if a service is running on a Linux system?

A: You can use the systemctl status command to check the status of a service. For example:

  • systemctl status apache2 checks if Apache is running. It shows whether the service is active, inactive, or failed.

 

Q47: How do you read the contents of a file without opening a text editor?

A: You can use commands like:

  • cat filename to display the entire file content.
  • less filename allows you to scroll through the file.
  • head filename shows the first 10 lines of the file.
  • tail filename shows the last 10 lines of the file.

 

Q48: What are environment variables, and how do you set them in Linux?

A: Environment variables are variables that store system-wide settings for processes and users, such as the path to executables or language preferences. To set an environment variable, use the export command. For example:

  • export PATH=$PATH:/new/directory adds a directory to the PATH variable.

 

Q49: What does the ps command do in Linux?

A: The ps command shows a snapshot of running processes on your system. You can use ps aux to view all running processes along with their details like memory and CPU usage.

 

Q50: How can you schedule a one-time task to run at a specific time in Linux?

A: You can use the at command to schedule tasks for a specific time. For example:

  • at 15:00 allows you to enter commands that will run at 3 PM.
  • Type the command you want to run, press Ctrl+D to save, and the task will execute at the specified time.

To explore more do visit: Click Here

 

Author:-

Gandhar Bodas

Call the Trainer and Book your free demo Class For Linux Call now!!!
| SevenMentor Pvt Ltd.

© Copyright 2021 | SevenMentor Pvt Ltd.