99 Linux Interview Questions

99 linux interview questions

Alright, how are you friends? There are 100 Linux interview questions in this article. They have short answers. They are for professionals with 2-4 years of experience. Whether you are preparing for an interview or need a quick revision of whatever you have learned, this article will be helpful for you.

Let’s get started.

Q1: What is Linux and what are its main features?

A: Linux is an open-source and free operating system based on Unix. It is safe, flexible, stable, and can run on hardware with minimum specification.

Q2: What is the difference between Linux and Unix?

A: Both are operating systems. However, Linux is free and Unix is proprietary. Linux is widely used by many users and unix is used by enterprises.

Q3: What is the Linux Kernel?

A: Kernel is the main component of Linux which provides an interface between software and hardware. It manages computer resources, processes, files, and operating system security.

Q4: What is a shell in Linux?

A: Shell is an interface between the user and Linux OS. It takes the commands from the user, gets executed from the OS, and returns the result.

Q5: What are common shells in Linux?

A: Bash, Korn Shell, Zsh, Tcsh etc.

To check which shell you are using, run the following on the terminal.

echo $SHELL

Q6: How do you create a new user in Linux?

A: You can create a new user using useradd command. You need sudo privileges for this command.

Suppose you want to create a new user ‘tony’, execute the following.

useradd tony

After executing the below command, you will notice that a personal folder has been created inside the home directory.

Q7: What is the root user in Linux?

A: The root user in Linux is a super user who has all the privileges of the system.

Q8: Explain the file permissions in Linux.

A: In Linux, there are three types of permissions which include read r, write w, and execute x for owner, group, and others.

When you execute ls -l, you will see something similar to the following:

From left to write, the first letter d indicates it is a directory. Owner root has read, write, and execute (rwx) permissions, group root has read and execute permissions (r-x), while other users have also read and execute permissions (r-x).

Q9: How do you change file permissions in Linux?

A: You can change the file permissions using chmod command.

Suppose you have a file ftp_testfile.txt. Other users have only read permission as you can see from the below screenshot.

If you want to assign write permission to others, you will have to run the following command on terminal. It’s very simple.

chmod o+w ftp_testfile.txt

If you again check the file permission of ftp_testfile.txt, you will notice that others have also write permission.

Q10: What is a process in Linux?

A: Process is an instance of a program. It is identified by a unique identifier called process ID or PID.

Q11: How do you view active processes in Linux?

A: You can view active processes using top, htop, and ps command.

Q12: How do you kill a process in Linux?

A: You can kill a process in Linux using kill command.

kill PID

Q13: What is a daemon in Linux?

A: Daemon is a process that runs continuously in the background. It typically starts at boot time.

Q14: What is the difference between a soft link and a hard link?

A: A soft link is a pointer to a file while the hard link is a direct mirror of a file. Deleting the original file will affect the soft link and not the hard link.

Q15: What is the use of df command in Linux?

A: The df command is used to display disk space usage of the file system. It displays the available and used disk memory of the system.

Q16: What does the free command do in Linux?

A: The free command displays the amount available and used of physical (RAM) and swap memory.

Q17: Explain the purpose of the grep command.

A: Grep command is used to search a text or string from a file.

grep “string” file.txt

You can also search the string from the output of a command using | operator.

ps -ef | grep firewall

Q18. How do you compress and extract files in Linux?

A: You can compress the file using gzip and extract it using gunzip.

Q19: What is a symbolic link in Linux?

A: A symbolic link and symlink is a file that points to another file or directory. It is a reference of some other file that can be used to open the target file.

Q20: What are inodes in Linux?

A: An inode is a unique identifier that is associated with a file or directory.

Q21: What is the purpose of crontab in Linux?

A: Crontab is used to schedule a task in Linux so that it can run automatically at a certain time.

Q22: How can you find the IP address of a Linux server?

A: You can find the IP address of a Linux server using ifconfig command.

Q23: Explain the purpose of sshd service.

A: sshd service is used to connect to a remote server.

Q24: How do you check the status of a service in Linux?

A: You can check the status of a service in Linux using systemctl command.

systemctl status servicename

Suppose, we want to check the status of sshd service. Run the following on terminal.

systemctl status sshd

As you can see from the screenshot, the service is active and running.

Q25: What is the purpose of the /etc/passwd file?

A: The /etc/passwd file contains user account information. We have just created the new user tony. You will read an entry in the file.

cat /etc/passwd

Q26: Explain the use of the vi editor.

A: It is a text editor which is used to create and edit files in Linux.

Q27: How do you search for a file in Linux?

A: You can use find and locate commands to search for a file in Linux.

Q28: What is the purpose of the iptables?

A: iptables is a default command line firewall in Ubuntu-based operating systems. With the help of iptables, you can define rules for how incoming and outgoing packets should behave and manipulated.

Q29: What are environment variables in Linux?

A: An environment variable is a named value that can affect the way running processes behave on a computer. E.g. printenv, shell etc.

Q30: How do you set an environment variable in Linux?

A: Environment variables can be set using export command.

E.g. Export VARNAME=value

Q31: What is the purpose of /etc/shadow file?

A: /etc/shadow file is used to store actual passwords of users in an encrypted format.

cat /etc/shadow

Q32: Explain the use of the ping command.

A: Ping command is used to test the reachability of a destination machine or server.

Q33: What is the difference between wget and curl?

A: Both are command-line tools for transferring data over the network. Wget is simpler and designed to download files whereas curl offers more protocols and features.

Q34: How do you check disk usage in Linux?

A: You can check the disk usage using df and du commands.

Q35: Explain the use of the tail command.

A: Tail command is used to read the last lines of any file. It is mostly used in log analysis.

Q36: What is the purpose of the xargs command?

A: xargs is used to build and execute command lines from standard input. It is useful for combining commands in a pipeline.

Q37: How do you schedule a task in Linux?

A: Task can be scheduled in Linux using crontab.

* * * * * /path/to/command

First star denotes minute, second star denotes hour, third star denotes day of month,

Q38: What is a package manager in Linux?

A: A package manager is a tool that is used to install, upgrade, configure, and remove packages from the Linux operating system.

Q39: Name some common package managers in Linux?

A: Common package managers are apt, yum, rpm, and zypper.

Q40:What is the difference between yum and rpm?

A: Yum automatically resolves package dependencies while rpm doesn’t.

Q41: How do you list all installed packages in Linux?

A: rpm -qa (red hat-based systems) and apt list –installed (ubuntu-based systems)

Q42: What is a Linux service?

A: It is a program that runs in the background.

Q43: How do you start, stop, and restart services in Linux?

A: we use systemctl command. E.g.

systemctl start servicename
systemctl stop servicename
systemctl restart servicename

Q44: Explain the purpose of the /etc/fstab file.

A: It is a configuration file that contains information of different file systems and how they are mounted.

Q45: What is LVM and what are its advantages?

A: LVM stands for logical volume manager. It allows for flexible disk management by creating, resizing, and deleting logical volumes.

Q46: How do you create a simple script in Linux?

A: You can create a simple script with the help of any text editor.

Suppose, I use nano editor to create a file test.sh.

nano test.sh

Assign executable permission to the user.

chmod u+x test.sh

Finally, run the script.

./test.sh

Q47: What is the use of the nohup command?

A: nohup command is used to run a command or script in the background even after logging out from the shell.

Q48: Explain the use of the sed command.

A: stream editor (sed) is used for parsing and transforming text. Suppose, you can use sed command to replace a specific word in a text file.

Q49: What is the purpose of the /var directory?

A: /var directory contains variable data like system logs, mail, and temporary files that are required for running applications.

Q50: How do you monitor system performance in Linux?

A: system performance can be measured using top, htop, iostat, and vmstat.

Q51: Explain the purpose of SSH command.

A: SSH stands for secure shell. It is a protocol that is used to securely access and manage a remote server.

Q52: How do you secure an SSH server?

A: SSH service can be secured by changing the default port, disabling root login, using key-based authentication, and configuring a firewall.

Q53: What is the purpose of the home directory?

A: The home directory contains the personal directories of all the users.

Q54: Explain the use of the awk command.

A: awk is a powerful programming language and tool used for pattern scanning and processing.

awk ‘{print $2}’ data.txt

Q55: How do you find the amount of free memory in the system?

A: You can find the amount of free memory by using the free command or by examining the contents of /proc/meminfo.

Q56: What is swap space in Linux?

A: Swap space is a portion of a hard disk which is used as RAM when the actual or physical RAM is full.

Q57: How do you create a swap file in Linux?

A: A swap file can be created by following three steps.

  1. dd to allocate space
  2. mkswap to set up a Linux swap area
  3. swapon to enable the swap file

Q58: What is the purpose of /etc/hosts file?

A: It is used to map hostnames to IP addresses.

Q59: How do you set a static IP address in Linux?

A: A static IP address is set by network configuration files or by using network management tools or commands depending upon the distribution.

Ex: nmcli or nmtui

Q60: Explain the purpose of the nslookup command. 

A: It is a network administration command-line tool used for querying the Domain Name System (DNS) to obtain domain name or IP address mapping.

nslookup

Q61: What is the difference between iptables and firewalld?

A: iptables is a traditional form of Linux firewall and firewalld is a more dynamic front end friendly tool that interfaces with iptables configurations.

Q62: How do you check the available memory slots and installed RAM in Linux?

A: You can check using dmidecode command or by examining /proc/meminfo.

Q63: What are runlevels in Linux?

A: These are predefined modes that a Linux system can run in. Each level has specific purpose, like single-user mode, multi-usermode, GUI mode etc.

Q64: How do you change runlevels?

A: Runlevels can be changed using the init/telinit command or systemctl in systemd-based systems.

Q65: What is the purpose of /boot directory?

A: It contains essential files needed to boot the system.

Q66: Explain the purpose of the rsync command.

A: rsync stands for remote sysnc. This command is used to copy files locally or remotely. It is normally used for copying backup.

Q67: What is a Linux distribution?

A: A Linux distribution is a flavor of the operating system that includes the kernel, package management system, and other supporting software and libraries.

Q68: Name some popular Linux distributions.

A: Ubuntu, Debian, CentOS, Linux Mint etc.

Q69: What are system logs and where are they located?

A: System logs records various activities of the operating system and they are located in /var/log directory.

var-log

Q70: Explain the purpose of the netstat command.

A: netstat command is used to display network connections, routing tables, interface statistics, and so on.

Q71: How do you add a new disk to a Linux system without rebooting?

A: You can add a new disk by scanning the SCSI bus using commands like echo “—” > /sys/class/scsi_host/host0/scan and then partitioning and formatting the new disk, then mount.

Q72: What is the purpose of the /etc/sysconfig directory?

A: /etc/sysconfig directory contains scripts and configuration files that manage the startup of services and configure aspects of system behavior.

Q73: How do you update all packages in Linux?

A: This can be done using the following commands.

Ubuntu based systems

apt-update && apt-upgrade

Red-hat based systems

yum update

Q74: What are the common network configuration files in Linux?

A: Common network configuration files include:

/etc/network/interfaces (Ubuntu-based systems)

/etc/sysconfig/network-scripts/ifcfg-eth0 (RHEL-based systems)

Q75: How do you change the default runlevel?

A: The default runlevel can be changed by editing the /etc/inittab file in SysVinit systems or by using systemctl set-default in systems systems.

Q76: What is the purpose of the /etc/resolve.conf file?

A: /etc/resolve.conf contains information about DNS servers and search domains for the host.

Q77. How do you find which process is using a particular file?

A: This can be found using the lsof command which lists open files and the processes using them.

Q78: What is the purpose of the dmesg command?

A: It displays the kernel-related messages and helps in troubleshooting hardware and driver-related issues.

Q79: Explain the purpose of the usermod command.

A: usermod is used to modify a user’s system properties such as username, home directory, and group.

Q80: How do you find the size of a directory in Linux?

A: The size of a directory can be found by using the du command.

Q81: What is the purpose of the /etc/cron.* directories?

A: These directories contain scripts that run periodically at fixed times, dates, or intervals by the cron daemon.

cron-directory

Q82: How do you change the priority of a process in Linux?

A: The priority of a process can be changed by renice command.

Q83: What is the purpose of the mount command?

A: mount command is used to attach a filesystem to a directory in the filesystem tree.

Q84: Explain the purpose of the umask command.

A: umask sets the default file creation permissions for new files and directories.

Q85: What is the purpose of the /opt directory?

A: /opt directory is used for storing optional software and packages that are not part of the default installation.

Q86: How do you find out which processes are listening on a specific port?

A: This can be found using netstat -tuln command.

Q87: Explain the purpose of the dig command.

A: DIG or Domain Information Groper is a network administration command-line tool for querying DNS name servers.

Q88: What is quota in Linux?

A: It is a system feature used to limit the amount of disk space and/or the number of files a user or group can use.

Q89: How do you set a quota for users in Linux?

A: Quotas are set using the quota and edquota commands, and by modifying filesystem configuration.

Q90: What is the purpose of the /usr directory?

A: /usr directory contains user utilities and applications, supporting files for the operating system.

Q91: How do you find the hardware details of your system?

A: Hardware details can be found using commands like lshw, lscpu, lsblk, and lscpi.

Q92: What is the purpose of the sysctl command?

A: sysctl is used to modify kernel parameters at runtime.

Q93: How do you check the kernel version of your Linux system?

A: The kernel version can be checked using uname -r.

uname-r

Q94: What is the difference between a service and daemon in Linux?

A: A daemon is a background process that runs continuously. A service is a process that performs a specific function and may not run continuously.

Q95: How do you redirect output in Linux?

A: Output can be redirected using the > for standard output and 2> for standard error.

Q96: What is the purpose of the /proc directory?

A: /proc is a virtual file system that provides a mechanism to access kernel and process information in a file-like structure.

Q97: Explain the purpose of the tr command.

A: tr is used for translating or deleting characters from standard input and writing to standard output.

Q98: What is the difference between PATH and LD_LIBRARY_PATH?

A: PATH is an environment variable specifying a set of directories where executable programs are located. LD_LIBRARY_PATH is used to specify a set of directories where libraries should be searched for first, before the standard set of directories.

Q99: How do you create a read-only file in Linux?

A: read-only file can be created using chmod command.

Thank you for reading the article. Keep visiting Linux World.