15 Linux OS Interview Questions and Answers
Prepare for your next technical interview with our comprehensive guide on Linux OS, featuring curated questions to enhance your understanding and skills.
Prepare for your next technical interview with our comprehensive guide on Linux OS, featuring curated questions to enhance your understanding and skills.
Linux OS is a cornerstone of modern computing, powering everything from personal devices to enterprise servers and cloud infrastructure. Known for its stability, security, and flexibility, Linux is an essential skill for IT professionals, system administrators, and developers. Its open-source nature allows for extensive customization and optimization, making it a preferred choice for many organizations.
This guide offers a curated selection of interview questions designed to test and enhance your understanding of Linux OS. By working through these questions, you will gain deeper insights into Linux’s core concepts and practical applications, preparing you to confidently tackle technical interviews and demonstrate your expertise.
The /etc directory in Linux is a central location for system configuration files, essential for the system’s operation. Key components include:
The structure is hierarchical, with subdirectories and files organized by function.
In Linux, each file and directory has an owner and permissions that determine access. Use chown
to change ownership and chmod
to change permissions.
Example to change ownership:
chown new_owner filename
Example to change permissions:
chmod 755 filename
Terminating a running process in Linux can be done using commands like kill
, pkill
, and killall
, which send signals to terminate processes.
Example:
# Terminate a process with a specific PID kill <PID> # Terminate all processes with a specific name pkill <process_name> # Terminate all instances of a process killall <process_name>
To install a package on a Debian-based system, use apt-get
or apt
.
Example:
sudo apt-get install package_name
For RPM-based systems like Red Hat, use yum
or dnf
.
Example:
sudo yum install package_name
To check the current IP address, use the ip
command.
Example:
ip addr show
To filter for IPv4 addresses:
ip -4 addr show | grep inet
To check available disk space, use df
for a summary of disk space and du
for file space usage.
Example with df
:
df -h
Example with du
:
du -sh /path/to/directory
System logs are typically stored in the /var/log directory. Use tools like cat
, less
, tail
, and grep
to view them.
Example to view the last few lines of syslog:
tail /var/log/syslog
To monitor in real-time:
tail -f /var/log/syslog
To add a new user, use the useradd
command followed by passwd
to set a password.
Example:
sudo useradd newusername sudo passwd newusername
Cron is a job scheduler that allows scheduling of periodic tasks. To schedule a daily backup, edit the crontab file.
Example:
crontab -e
Add a line for a daily backup at 2 AM:
0 2 * * * /path/to/backup.sh
To configure a static IP address, edit network configuration files or use command-line tools. The method varies by distribution.
Example for Ubuntu using Netplan:
network: version: 2 ethernets: eth0: dhcp4: no addresses: - 192.168.1.100/24 gateway4: 192.168.1.1 nameservers: addresses: - 8.8.8.8 - 8.8.4.4
Apply changes with:
sudo netplan apply
Logical Volume Manager (LVM) allows flexible disk management. To create and manage logical volumes:
bash
pvcreate /dev/sda1 /dev/sda2
bash
vgcreate my_volume_group /dev/sda1 /dev/sda2
bash
lvcreate -L 10G -n my_logical_volume my_volume_group
bash
mkfs.ext4 /dev/my_volume_group/my_logical_volume
bash
mount /dev/my_volume_group/my_logical_volume /mnt
bash
lvresize -L +5G /dev/my_volume_group/my_logical_volume
resize2fs /dev/my_volume_group/my_logical_volume
To troubleshoot a system that fails to boot:
fsck
.Securing a Linux server involves several practices:
To troubleshoot network connectivity issues:
1. Check network interface configuration with ifconfig
or ip addr
.
2. Verify connectivity using ping
.
3. Check routing table with route
or ip route
.
4. Verify DNS resolution with nslookup
or dig
.
5. Inspect firewall rules with iptables
or firewalld
.
6. Check network services with netstat
or ss
.
7. Review system logs with dmesg
, journalctl
, or tail -f /var/log/syslog
.
8. Use traceroute
to trace packet paths.
Monitor and manage system resources using tools like top, htop, and vmstat.