Linux Interview Questions
Q: What is the Linux kernel?
A: The Linux kernel is the core of the Linux operating system. It manages system resources, such as memory and CPU time, and provides a interface for interacting with hardware.
Q: What is the difference between a file and a directory in Linux?
A: A file is a single object that stores data, while a directory is a container for other files and directories.
Q: What is the purpose of the /etc directory in Linux?
A: The /etc directory contains configuration files for the system and applications.
Q: What is the difference between the 'ls' and 'ls -l' commands?
A: The 'ls' command lists the files and directories in a directory, while 'ls -l' lists the files and directories in a directory in a long format, including permissions, owner, and timestamp.
Q: How would you list all files in a directory, including hidden files?
A: You can use the command 'ls -a' to list all files in a directory, including hidden files.
Q: How would you check the current version of your Linux distribution?
A: You can use the command 'lsb_release -a' to check the version of your Linux distribution.
Q: How would you check the current system uptime in Linux?
A: You can use the command 'uptime' to check the current system uptime in Linux.
Q: How would you check the current system load in Linux?
A: You can use the command 'top' or 'uptime' to check the current system load in Linux.
Q: How would you check the current disk usage in Linux?
A: You can use the command 'df -h' to check the current disk usage in Linux.
Q: How would you check the current memory usage in Linux?
A: You can use the command 'free -m' to check the current memory usage in Linux.
Q: What is a Linux distribution?
A: A Linux distribution is a version of the Linux operating system that is packaged with various software and tools. Examples include Ubuntu, Debian, and Red Hat.
Q: What is the difference between a soft link and a hard link?
A: A soft link (or symbolic link) is a pointer to a file or directory that is stored in a separate location, while a hard link is a direct link to the actual file or directory.
Q: How do you check system uptime?
A: You can check the system uptime using the 'uptime' command.
Q: How do you check the version of your Linux distribution?
A: You can check the version of your Linux distribution by running the 'lsb_release -a' command.
Q: How do you check the available disk space on a Linux system?
A: You can check the available disk space using the 'df' command.
Q: What is the difference between 'ps' and 'top' commands?
A: The 'ps' command shows all processes running on the system, while 'top' command shows the processes that are currently using the most system resources.
Q: What is the use of 'chmod' command?
A: The 'chmod' command is used to change the permissions of a file or directory.
Q: How do you configure a static IP address on a Linux system?
A: You can configure a static IP address by editing the 'network' configuration file '/etc/network/interfaces' and updating the IP address, subnet mask, gateway, and DNS server settings.
Q: What is the use of 'sudo' command?
A: The 'sudo' command allows a user to execute a command with root privileges.
Q: How do you install a package on a Linux system?
A: You can install a package on a Linux system using a package manager such as apt, yum or dnf depending on the distribution you are using.
Q: What is Linux?
A: Linux is a free and open-source operating system based on the Unix operating system.
Q: What is the difference between Linux and Windows?
A: Linux is open-source and free to use, whereas Windows is proprietary and requires a license. Linux is also known for its stability, security, and flexibility.
Q: What is a Linux distribution?
A: A Linux distribution, also known as a "distro," is a version of Linux that includes specific software packages, configuration settings, and other features. Some popular Linux distributions include Ubuntu, Debian, and Red Hat.
Q: What is the command line?
A: The command line, also known as the "terminal," is a text-based interface for interacting with the operating system. It allows users to enter commands and receive output, rather than using a graphical user interface (GUI).
Q: How would you check the system's uptime?
A: The uptime command shows the time since the system was last booted.
Q: How would you check the system's load average?
A: The top command provides a real-time view of system performance, including the load average.
Q: How would you check the system's memory usage?
A: The free command shows the amount of free and used memory in the system.
Q: How would you check the system's disk usage?
A: The df command shows the amount of free and used space on the system's file systems.
Q: How would you install a new software on Linux?
A: The apt-get command for Debian based distributions or yum command for RedHat based distributions are used to install new software.
Q: How would you setup a firewall on Linux?
A: The iptables command is used to configure the Linux firewall.
Q: How would you configure a new user on Linux?
A: The useradd or adduder command is used to create a new user, and the passwd command is used to set the user's password.
Q: How would you add a new user to a group?
A: The usermod command is used to add a user to a group.
Q: How would you check the status of a service on Linux?
A: The service or systemctl command is used to check the status of a service on Linux.
Q: How would you start/stop/restart a service on Linux?
A: The service or systemctl command is used to start/stop/restart a service on Linux.
Q: How would you configure a new network interface on Linux?
A: The ifconfig command is used to configure a new network interface on Linux.
Q: What is the purpose of the /etc/passwd file?
A: The /etc/passwd file is a text file that stores information about user accounts on a Linux system, including the username, user ID (UID), group ID (GID), and home directory.
Q: What is the purpose of the /etc/shadow file?
A: The /etc/shadow file is a text file that stores password information for user accounts on a Linux system. It is used to store hashed passwords and password aging information, and is only accessible by the root user.
Q: How do you check the current version of the Linux kernel?
A: To check the current version of the Linux kernel, you can use the command "uname -r"
Q: How do you check the amount of free disk space on a Linux system?
A: To check the amount of free disk space on a Linux system, you can use the command "df -h"
Q: How do you check for open ports on a Linux system?
A: To check for open ports on a Linux system, you can use the command "netstat -an"
Q: How do you check for running processes on a Linux system?
A: To check for running processes on a Linux system, you can use the command "ps aux"
Q: How do you check the current users logged into a Linux system?
A: To check the current users logged into a Linux system, you can use the command "w"
Q: How do you check the uptime of a Linux system?
A: To check the uptime of a Linux system, you can use the command "uptime"
Q: How do you check the amount of memory used by a Linux system?
A: To check the amount of memory used by a Linux system, you can use the command "free -m"
Q: How do you check the load average of a Linux system?
A: To check the load average of a Linux system, you can use the command "uptime"
Q: How do you find the location of a command on a Linux system?
A: To find the location of a command on a Linux system, you can use the command "which [command]"
Q: How do you check the status of a service on a Linux system?
A: To check the status of a service on a Linux system, you can use the command "systemctl status [service]"
Q: How do you manage and configure services on a Linux system?
A: To manage and configure services on a Linux system, you can use the command "systemctl" or "service" command. For example, to start, stop, restart or check the status of a service, you can use the command "systemctl start/stop/restart/status [service]"
Q: How do you schedule tasks on a Linux system?
A: To schedule tasks on a Linux system, you can use the "cron" daemon. This daemon runs in the background and checks for scheduled tasks in the /etc/crontab and /etc/cron./ files. You can schedule tasks using the "crontab -e" command and specify the schedule in the format of "* * * * * command"
Q: How do you check system logs on a Linux system?
A: To check system logs on a Linux system, you can use the command "tail" or "cat" to read the contents of the log files located in the /var/log directory. You can also use the "journalctl" command to view logs stored by the systemd logging system.
Q: How do you manage and configure network settings on a Linux system?
A: To manage and configure network settings on a Linux system, you can use the command "ifconfig" or "ip addr" to view the current network configuration and "vi" or "nano" command to edit the network configuration files located in the /etc/network/interfaces directory.
Q: How do you configure and manage firewalls on a Linux system?
A: To configure and manage firewalls on a Linux system, you can use the "iptables" command to set up firewall rules, and "iptables-save" and "iptables-restore" to save and restore firewall rules. Alternatively, you can use the "ufw" command to manage the firewall.
Q: How do you manage and configure storage on a Linux system?
A: To manage and configure storage on a Linux system, you can use the command "fdisk", "parted" or "gparted" to partition and format the storage devices. You can also use the "mount" command to mount file systems and the "df" command to check the available space on the mounted file systems.
Q: How do you perform backups and restore on a Linux system?
A: To perform backups and restore on a Linux system, you can use the command "tar" or "cpio" to create backups of files and directories, and "rsync" to synchronize files and directories between systems. You can also use "dd" command to create image backups of the entire system.
Q: What is the purpose of the Linux operating system and what are some of its key features?
A: The purpose of the Linux operating system is to provide a free, open-source alternative to proprietary operating systems. Some key features include its stability, security, flexibility, and support for a wide range of hardware and software platforms.
Q: How do you manage and configure Linux servers?
A: Linux servers can be managed and configured through various command-line tools such as the terminal, SSH, and remote desktop protocols. Additionally, graphical user interface (GUI) tools like Webmin and cPanel can also be used.
Q: What is the difference between a physical and a virtual server?
A: A physical server is a physical piece of hardware that is dedicated to running a server operating system. A virtual server, on the other hand, is a software-based simulation of a physical server that runs on top of a host operating system.
Q: What is the difference between a process and a thread?
A: A process is an instance of a program that is being executed by the operating system. A thread is a lightweight, independent unit of execution within a process that can run in parallel with other threads.
Q: How do you manage and troubleshoot Linux services?
A: Linux services can be managed and troubleshooted using command-line tools such as systemctl, service, and chkconfig. Additionally, log files and monitoring tools can also be used to diagnose and resolve issues with Linux services.
Q: How do you manage and troubleshoot Linux storage?
A: Linux storage can be managed and troubleshooted using command-line tools such as fdisk, parted, and lvm. Additionally, monitoring tools such as iostat and sar can be used to track storage usage and performance.
Q: How do you secure a Linux server?
A: Securing a Linux server involves implementing a variety of security measures such as setting strong passwords, disabling unnecessary services and accounts, using firewalls, implementing intrusion detection and prevention systems, and regularly updating software and security patches.
Q: What is the difference between a distribution and a package manager?
A: A Linux distribution is a version of the Linux operating system that is packaged with a specific set of software and tools. A package manager is a tool that is used to install, update, and manage software packages on a Linux system. Examples of package manager include apt, yum, and dnf.
Q: How do you set up a firewall on a Linux system?
A: Firewalls can be set up on a Linux system using tools such as iptables, ufw, and firewalld. These tools allow you to configure rules and policies to control incoming and outgoing network traffic.
Q: How do you configure and troubleshoot networking on a Linux system?
A: Networking on a Linux system can be configured and troubleshooted using command-line tools such as ifconfig, route, and netstat. Additionally, log files and monitoring tools can also be used to diagnose and resolve issues with networking.
Q: How do you manage and troubleshoot Linux security?
A: Linux security can be managed and troubleshooted using command-line tools such as chkrootkit, rkhunter, and tripwire. Additionally, monitoring tools such as PSAD and OSSEC can be used to track and alert on security-related events.
Q: How do you perform backups and disaster recovery on a Linux system?
A: Backups and disaster recovery on a Linux system can be performed using command-line tools such as tar, rsync, and dump. Additionally, backup software such as Bacula, Amanda, and Veeam can also be used to automate and schedule backups.
Q: How do you monitor and troubleshoot system performance on a Linux system?
A: System performance on a Linux system can be monitored and troubleshooted using command-line tools such as top, vmstat, and iostat. Additionally, monitoring tools such as Nagios, Zabbix, and Prometheus can also be used to track and alert on system performance metrics.
Q: What are Soft limits and Hard limits in Linux?
A: In Linux, "soft limits" and "hard limits" refer to the limits that can be placed on certain system resources for individual users or processes.
A "soft limit" is the maximum limit that can be set for a particular resource, such as the amount of memory a user can use, but the user can temporarily exceed the limit if no one else is using the resource.
A "hard limit," on the other hand, is the absolute maximum limit that cannot be exceeded, regardless of whether or not other resources are being used.
For example, a user might have a soft limit of 100MB of memory and a hard limit of 256MB. The user can temporarily use more than 100MB of memory if no one else is using it, but they cannot exceed 256MB at any time.
The system administrator can set the soft and hard limits using the ulimit command or through system configuration files.
Q: Nice and Renice Command in Linux with Examples
A: The "nice" command in Linux is used to change the priority of a process, which determines how much of the system's resources (such as CPU time) the process is allocated. A process with a higher priority will get more resources, while a process with a lower priority will get less.
The basic syntax for the "nice" command is:
nice -n [priority] [command]
For example, to run the "find" command with a priority of 10, you would use the following command:
nice -n 10 find / -name file.txt
The "renice" command is used to change the priority of a running process. The basic syntax for the "renice" command is:
renice [priority] -p [pid]
For example, to change the priority of a process with PID 12345 to 10, you would use the following command:
renice 10 -p 12345
It is worth noting that the priority value is inverted, a lower numerical value means a higher priority. On most systems, the default range for the nice values is from -20 (highest priority) to 19 (lowest priority).
Q: Linux vs Unix:
A: Linux and Unix are both operating systems, but there are some key differences between them.
Unix is a proprietary operating system developed in the 1970s by AT&T Bell Labs. It is widely used in servers and supercomputers and is known for its stability and security. Unix is also the basis for many other operating systems, including Linux.
Linux, on the other hand, is a free and open-source operating system that was first released in 1991. It is also based on the Unix operating system, but it is developed and maintained by a large community of volunteer programmers. Linux is known for its flexibility and is often used as an alternative to proprietary operating systems like Windows and MacOS.
In summary, Linux is a free and open-source operating system that is based on Unix and developed by a community of volunteer programmers, while Unix is a proprietary operating system developed by AT&T Bell Labs and widely used in servers and supercomputers.
Q: Access Control Lists (ACLs) with examples:
A: In Linux, Access Control Lists (ACLs) are used to specify fine-grained permissions for files and directories beyond the standard read, write, and execute permissions. ACLs allow you to assign permissions to specific users or groups on a file or directory, rather than just the owner and group owner.
Here's an example of how to set an ACL on a file in Linux:
First, you need to make sure that the file system is mounted with the "acl" option. You can check this by running the command "mount" and looking for the "acl" option listed for the file system containing the file.
Next, you can set an ACL on a file using the "setfacl" command. For example, to give user "jane" read and execute permissions on the file "example.txt", you would run the following command:
setfacl -m u:jane:rx example.txt
To give read and execute permissions to the group "marketing" on the same file you would run:
setfacl -m g:marketing:rx example.txt
To check the current permissions on a file, you can use the "getfacl" command, like so:
getfacl example.txt
This will show the standard file permissions as well as any additional permissions set through ACLs.
Note that this is just a simple example, and ACLs can be used in many more complex ways, such as giving permissions to specific users, groups, or even to anonymous users.
In order to remove a user or group specific entry from a file, you would specify the x option.
setfacl -x u:<user> <file, directory>
setfacl -x g:<group> <file, directory>
Q: What is SWAP?
A: In Linux, swap is a space on a hard drive that is used as an extension of the computer's physical memory (RAM). It is used when the system runs out of RAM and needs to move some of the data from RAM to the hard drive in order to free up space. This process is called "swapping."
Swap space can be created on a hard drive by using the "mkswap" command, and it can be activated and deactivated with the "swapon" and "swapoff" commands, respectively. Once activated, the kernel will begin using swap space as a place to store data that is no longer being used by the system, but may be needed again in the future. This way, when the system needs more RAM to run new programs, it can quickly retrieve the data from swap space and move it back into RAM, rather than having to load it from the hard drive, which is much slower.
It's important to have enough swap space to handle the maximum amount of RAM that a computer might have. Some general guidelines suggest having 1.5 times the amount of RAM as swap space, however it depends on the usage of the system and the type of workloads it's running.
No comments: