50 Linux Interview Questions with Answers

Share with friends
Save Story for Later (0)
Please login to bookmark Close

Basic Commands and Concepts

  1. What is Linux?
    • Answer: Linux is an open-source operating system kernel based on Unix. It is widely used for server environments, desktops, and embedded systems. Linux distributions combine the kernel with other software to form complete operating systems.
  2. What is a Linux distribution?
    • Answer: A Linux distribution (or distro) is a complete operating system built around the Linux kernel. Examples include Ubuntu, CentOS, Fedora, and Debian. Each distribution includes the kernel, system libraries, and application software.
  3. How do you list files in a directory?
    • Answer: Use the ls command. For example, ls -l provides a detailed listing of files including permissions, owner, size, and modification date.
  4. What does the cd command do?
    • Answer: The cd (change directory) command is used to navigate between directories in the file system.
  5. How do you check the current working directory?
    • Answer: Use the pwd (print working directory) command to display the full path of the current directory.
  6. How do you create a new directory?
    • Answer: Use the mkdir command followed by the name of the directory you want to create. For example, mkdir new_directory.
  7. How do you remove a file?
    • Answer: Use the rm command followed by the name of the file. For example, rm file.txt. Use rm -r to remove directories and their contents recursively.
  8. What does the cp command do?
    • Answer: The cp command is used to copy files or directories from one location to another. For example, cp source.txt destination.txt.
  9. How do you move or rename a file?
    • Answer: Use the mv command. For example, mv old_name.txt new_name.txt renames a file, and mv file.txt /path/to/destination/ moves a file to a different directory.
  10. How do you view the contents of a file?
    • Answer: Use commands like cat, more, or less. For example, cat file.txt displays the entire file content, while less file.txt allows for scrolling through the file.

File Permissions and Ownership

  1. What do file permissions like rwxr-xr-x mean?
    • Answer: These permissions indicate read (r), write (w), and execute (x) permissions for the owner, group, and others. In rwxr-xr-x, the owner has full permissions, the group has read and execute permissions, and others have read and execute permissions.
  2. How do you change file permissions?
    • Answer: Use the chmod command. For example, chmod 755 file.txt sets the permissions to rwxr-xr-x.
  3. How do you change the ownership of a file?
    • Answer: Use the chown command. For example, chown user:group file.txt changes the ownership of file.txt to user and group.
  4. What does the umask command do?
    • Answer: The umask command sets default permissions for new files and directories. It determines the permissions that are not set when a new file or directory is created.
  5. How do you find out which user you are currently logged in as?
    • Answer: Use the whoami command to display the current user.

System Information and Management

  1. How do you check the systemโ€™s disk usage?
    • Answer: Use the df command to check disk space usage. For example, df -h provides human-readable sizes.
  2. How do you check the memory usage on a Linux system?
    • Answer: Use the free command to display memory usage. For example, free -h provides human-readable sizes.
  3. How do you display the running processes on a system?
    • Answer: Use the ps command or top command. For example, ps aux lists all running processes, while top provides a real-time view.
  4. What does the uname command do?
    • Answer: The uname command provides system information. For example, uname -a displays all available system information including the kernel version.
  5. How do you find the IP address of a Linux system?
    • Answer: Use the ip a or ifconfig command. For example, ip a shows detailed network information, including IP addresses.

Networking and Connectivity

  1. How do you test network connectivity to a remote host?
    • Answer: Use the ping command. For example, ping google.com tests connectivity to Googleโ€™s servers.
  2. How do you check which ports are open on your Linux system?
    • Answer: Use the netstat -tuln command or ss -tuln command to list open ports and listening services.
  3. What is the traceroute command used for?
    • Answer: The traceroute command shows the path packets take from your system to a remote host, including intermediate routers.
  4. How do you configure a static IP address on a Linux system?
    • Answer: Edit the network configuration files, such as /etc/network/interfaces for Debian-based systems or /etc/sysconfig/network-scripts/ifcfg-eth0 for Red Hat-based systems, and set the static IP address configuration.
  5. What does the route command do?
    • Answer: The route command is used to display or modify the IP routing table. For example, route -n shows the routing table.

Package Management

  1. How do you install a package on a Debian-based system?
    • Answer: Use the apt-get or apt command. For example, sudo apt-get install package_name.
  2. How do you update the package list on a Red Hat-based system?
    • Answer: Use the yum or dnf command. For example, sudo yum update or sudo dnf update.
  3. How do you remove a package on a Debian-based system?
    • Answer: Use the apt-get remove or apt remove command. For example, sudo apt-get remove package_name.
  4. How do you search for a package on a Linux system?
    • Answer: Use the apt-cache search command on Debian-based systems or yum search on Red Hat-based systems. For example, apt-cache search package_name.
  5. How do you list installed packages on a Debian-based system?
    • Answer: Use the dpkg -l command to list all installed packages.

System Configuration and Maintenance

  1. How do you check system logs on a Linux system?
    • Answer: System logs are typically located in /var/log. Use commands like cat, less, or tail to view log files. For example, cat /var/log/syslog.
  2. How do you schedule tasks in Linux?
    • Answer: Use the cron service to schedule recurring tasks. Edit the crontab file using crontab -e to add scheduled tasks. For one-time tasks, use the at command.
  3. How do you change the hostname of a Linux system?
    • Answer: Use the hostnamectl command to change the hostname. For example, sudo hostnamectl set-hostname new_hostname.
  4. What is systemd and how do you use it?
    • Answer: systemd is an init system and service manager used in many Linux distributions. Commands like systemctl start service, systemctl stop service, and systemctl status service manage services.
  5. How do you add a new user to a Linux system?
    • Answer: Use the useradd command followed by the username. For example, sudo useradd username and set a password with sudo passwd username.

Security and Permissions

  1. How do you check the last logins on a Linux system?
    • Answer: Use the last command to display a list of recent logins.
  2. How do you lock and unlock a user account?
    • Answer: Use passwd -l username to lock an account and passwd -u username to unlock it.
  3. What is the purpose of sudo?
    • Answer: sudo (superuser do) allows a permitted user to execute commands with superuser privileges or other usersโ€™ privileges, as defined in the /etc/sudoers file.
  4. How do you check the status of a service in Linux?
    • Answer: Use the systemctl status service_name command to check the status of a service managed by systemd.
  5. How do you manage file and directory permissions in Linux?
    • Answer: Use the chmod command to change permissions, chown to change ownership, and chgrp to change group ownership.

Advanced Topics

  1. What is a Linux kernel module?
    • Answer: A kernel module is a piece of code that can be loaded into the kernel to extend its functionality, such as adding support for hardware or file systems.
  2. How do you load and unload kernel modules?
    • Answer: Use modprobe to load or unload modules. For example, modprobe module_name to load and modprobe -r module_name to unload.
  3. How do you view and configure system services in Linux?
    • Answer: Use systemctl commands to manage and configure system services. For example, systemctl enable service_name to enable a service at boot.
  4. What is the lsof command used for?
    • Answer: The lsof command lists open files and the processes using them. It helps in identifying which processes are accessing specific files or ports.
  5. How do you create and manage disk partitions in Linux?
    • Answer: Use tools like fdisk, parted, or gparted to create and manage disk partitions. For example, fdisk /dev/sda to manage partitions on /dev/sda.
  6. What is the purpose of the /etc/fstab file?
    • Answer: The /etc/fstab file defines the file systems to be mounted at boot time and their mount options.
  7. How do you monitor system performance in Linux?
    • Answer: Use commands like top, htop, vmstat, and iostat to monitor system performance metrics such as CPU, memory, and I/O usage.
  8. How do you create a symbolic link in Linux?
    • Answer: Use the ln -s command. For example, ln -s target_file symbolic_link creates a symbolic link named symbolic_link that points to target_file.
  9. What is the chmod command used for?
    • Answer: chmod changes the file permissions of a file or directory. For example, chmod 755 file.txt sets the permissions to rwxr-xr-x.
  10. How do you handle log rotation in Linux?
    • Answer: Use the logrotate utility to manage log rotation. It compresses, rotates, and removes old log files based on configuration specified in /etc/logrotate.conf and /etc/logrotate.d/.

Article Contributors

  • Dr. Errorstein
    (Author)
    Director - Research & Innovation, QABash

    A mad scientist bot, experimenting with testing & test automation to uncover the most elusive bugs.

  • Ishan Dev Shukl
    (Reviewer)
    SDET Manager, Nykaa

    With 13+ years in SDET leadership, I drive quality and innovation through Test Strategies and Automation. I lead Testing Center of Excellence, ensuring high-quality products across Frontend, Backend, and App Testing. "Quality is in the details" defines my approachโ€”creating seamless, impactful user experiences. I embrace challenges, learn from failure, and take risks to drive success.

Subscribe to QABash Weekly ๐Ÿ’ฅ

Dominate โ€“ Stay Ahead of 99% Testers!

Leave a Reply

Scroll to Top