Linux-Interview Questions
What are the Linux flavors?
- Linux distributions or flavors include Ubuntu, CentOS, Debian, Fedora, Red Hat Enterprise Linux (RHEL), and many others. Each has its own package management system and configurations but shares the Linux kernel at its core.
What is process management?
- Process management in Linux involves monitoring, controlling, and organizing processes running on the system. This includes starting, stopping, prioritizing, and managing resources allocated to processes.
How to create a User? and How to give permissions to the user.
To create a user:
sudo adduser username
To give permissions: Use
chmod
to change file permissions orchown
to change ownership.
How do you add a user to an Existing Group In Linux?
sudo usermod -aG groupname username
How to change the owner permissions of the User or the file?
sudo chown newowner filename
to change ownership.sudo chmod permissions filename
to change permissions.
How to check the disk space in Linux?
df -h
for overall disk usage.du -h
for usage by specific directories.
How to check memory in Linux?
free -h
for overall memory usage.top
orhtop
for a dynamic view of memory usage by processes.
What does the top command display?
- The
top
command displays real-time information about processes, CPU usage, memory usage, and system uptime.
- The
What is the use of lsblk command in Linux?
lsblk
lists information about block devices (like disks and partitions) in a tree-like format.
How to do Disk partition in Ubuntu?
- Use
fdisk
,parted
, orgparted
tools to create, delete, and manage disk partitions.
- Use
Where is fstab in Linux?
/etc/fstab
is a configuration file that contains information about filesystems and storage devices, including mount points and options.
What is the Linux boot process?
- The Linux boot process involves BIOS/UEFI initialization, bootloader (like GRUB) loading the kernel, kernel initialization, and starting of system services and user-space processes.
What is a Linux filesystem? What is /etc and /bin?
- A Linux filesystem organizes how data is stored and retrieved on disk.
/etc
contains system-wide configuration files, while/bin
holding essential binary executables.
- A Linux filesystem organizes how data is stored and retrieved on disk.
What are Crontab and Cronjob?
Crontab
is the command used to edit cron jobs.Cronjobs
are scheduled tasks that run at specified intervals or times automatically.
What is virtualization?
- Virtualization allows multiple virtual instances of operating systems or applications to run on a single physical machine, enabling efficient resource utilization.
What is SElinux?
- SELinux (Security-Enhanced Linux) is a Linux kernel security module that provides access control security policies, including mandatory access controls (MAC).
How DNS works?
- DNS (Domain Name System) translates domain names (like example.com) into IP addresses that computers use to communicate over networks.
What is Apache?
- Apache HTTP Server is a widely used open-source web server software that delivers web content to clients over the internet.
What is PHPAdmin?
- phpMyAdmin is a free and open-source tool written in PHP that manages MySQL databases through a web interface.
Do you know about firewalls?
- Firewalls are network security systems that monitor and control incoming and outgoing network traffic based on predetermined security rules.
What is an SSL certificate? How can we create the SSL certificate and where will we do the configurations in Apache for the SSL certificate?
- An SSL certificate encrypts data exchanged between a web server and a client. It can be created using tools like OpenSSL. Configuration for SSL in Apache is done in the virtual host configuration files.
Which is better, Apache or Nginx? For a higher load, which web server is best?
- Nginx is often preferred for serving static content and handling concurrent connections efficiently, making it suitable for high-load scenarios. Apache is versatile and supports a wide range of configurations and modules.
What is the path of Apache configuration files?
- Apache configuration files are typically found in
/etc/apache2/
on Ubuntu or/etc/httpd/
on CentOS.
- Apache configuration files are typically found in
๐๐ ๐ฒ๐จ๐ฎ ๐ฐ๐๐ง๐ญ ๐ญ๐จ ๐ซ๐ฎ๐ง ๐ ๐ญ๐๐ฌ๐ค/๐ฌ๐๐ซ๐ข๐ฉ๐ญ ๐ข๐ง ๐๐๐๐ค๐ ๐ซ๐จ๐ฎ๐ง๐ ๐๐ฏ๐๐ง ๐ข๐ ๐ฒ๐จ๐ฎ ๐๐ฅ๐จ๐ฌ๐ ๐ฒ๐จ๐ฎ๐ซ ๐ญ๐๐ซ๐ฆ๐ข๐ง๐๐ฅ, ๐ฐ๐ก๐๐ญ ๐ข๐ฌ ๐ญ๐ก๐ ๐ฐ๐๐ฒ?
Ans: Using nohup command
๐๐ก๐ข๐๐ก ๐๐จ๐ฆ๐ฆ๐๐ง๐ ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ๐ฌ ๐ข๐ง๐๐จ๐ซ๐ฆ๐๐ญ๐ข๐จ๐ง ๐๐๐จ๐ฎ๐ญ ๐ค๐๐ซ๐ง๐๐ฅ-๐ซ๐๐ฅ๐๐ญ๐๐ ๐ฆ๐๐ฌ๐ฌ๐๐ ๐๐ฌ ๐๐ฅ๐จ๐ง๐ ๐ฐ๐ข๐ญ๐ก ๐ก๐๐ซ๐๐ฐ๐๐ซ๐ ๐๐ง๐ ๐ฌ๐ฒ๐ฌ๐ญ๐๐ฆ ๐ฌ๐ญ๐๐ซ๐ญ๐ฎ๐ฉ ๐ฆ๐๐ฌ๐ฌ๐๐ ๐๐ฌ ๐ฌ๐ญ๐จ๐ซ๐๐ ๐ข๐ง ๐ค๐๐ซ๐ง๐๐ฅ ๐ซ๐ข๐ง๐ ๐๐ฎ๐๐๐๐ซ?
Ans: dmesg command
๐๐ก๐ข๐๐ก ๐๐จ๐ฆ๐ฆ๐๐ง๐ ๐๐๐ง ๐ฒ๐จ๐ฎ ๐ฎ๐ฌ๐ ๐ญ๐จ ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ ๐ ๐ฅ๐ข๐ฌ๐ญ ๐จ๐ ๐๐ฎ๐ซ๐ซ๐๐ง๐ญ๐ฅ๐ฒ ๐๐จ๐ง๐๐ข๐ ๐ฎ๐ซ๐๐ ๐๐ก๐ฒ๐ฌ๐ข๐๐๐ฅ ๐๐จ๐ฅ๐ฎ๐ฆ๐๐ฌ?
Ans: lvs command
๐๐ก๐ข๐๐ก ๐๐จ๐ฆ๐ฆ๐๐ง๐ ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ๐ฌ ๐ฆ๐๐ฆ๐จ๐ซ๐ฒ ๐ฎ๐ฌ๐๐ ๐, ๐ข๐ง๐๐ฅ๐ฎ๐๐ข๐ง๐ ๐ญ๐ก๐ ๐๐ฆ๐จ๐ฎ๐ง๐ญ ๐จ๐ ๐ฌ๐ฐ๐๐ฉ ๐ฌ๐ฉ๐๐๐ ๐๐๐ข๐ง๐ ๐ฎ๐ฌ๐๐?
Ans: free command
๐๐ก๐ /๐ก๐จ๐ฆ๐ ๐ฉ๐๐ซ๐ญ๐ข๐ญ๐ข๐จ๐ง ๐ข๐ฌ ๐ซ๐ฎ๐ง๐ง๐ข๐ง๐ ๐จ๐ฎ๐ญ ๐จ๐ ๐๐ข๐ฌ๐ค ๐ฌ๐ฉ๐๐๐. ๐๐ก๐ข๐๐ก ๐๐จ๐ฆ๐ฆ๐๐ง๐ ๐๐๐ง ๐ฒ๐จ๐ฎ ๐ฎ๐ฌ๐ ๐ญ๐จ ๐๐๐ญ๐๐ซ๐ฆ๐ข๐ง๐ ๐ฐ๐ก๐ข๐๐ก ๐ฎ๐ฌ๐๐ซ'๐ฌ ๐ก๐จ๐ฆ๐ ๐๐ข๐ซ๐๐๐ญ๐จ๐ซ๐ฒ ๐ข๐ฌ ๐ฎ๐ฌ๐ข๐ง๐ ๐ญ๐ก๐ ๐ฆ๐จ๐ฌ๐ญ ๐ฌ๐ฉ๐๐๐?
Ans: we can use du command
๐๐จ๐ฐ ๐ญ๐จ ๐๐ก๐๐๐ค ๐ฒ๐จ๐ฎ๐ซ ๐๐ข๐ง๐ฎ๐ฑ ๐ ๐ข๐ฅ๐๐๐ฒ๐ฌ๐ญ๐๐ฆ?
Ans: lsblk -f
๐๐จ๐ฐ ๐ญ๐จ ๐๐๐๐ ๐ญ๐ก๐ ๐๐จ๐ง๐ญ๐๐ง๐ญ ๐๐ซ๐จ๐ฆ ๐ ๐๐ข๐ฅ๐ ๐ข๐ง ๐๐ข๐ง๐ฎ๐ฑ?
Ans: sort -r file
๐๐จ๐ฐ ๐ญ๐จ ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ ๐๐๐๐๐๐ ๐๐จ๐ง๐ญ๐๐ง๐ญ ๐๐ซ๐จ๐ฆ ๐ ๐๐ข๐ฅ๐ ๐ข๐ง ๐๐ข๐ง๐ฎ๐ฑ?
Ans: sort file | uniq
๐๐จ๐ฐ ๐ญ๐จ ๐ฌ๐๐๐ซ๐๐ก ๐ฆ๐ฎ๐ฅ๐ญ๐ข๐ฉ๐ฅ๐ ๐ฐ๐จ๐ซ๐๐ฌ ๐๐ง๐ ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ ๐ฆ๐๐ญ๐๐ก๐ข๐ง๐ ๐๐จ๐ง๐ญ๐๐ง๐ญ ๐๐ซ๐จ๐ฆ ๐ ๐๐ข๐ฅ๐ ๐ข๐ง ๐๐ข๐ง๐ฎ๐ฑ?
Ans: egrep "word1|word2" file
๐๐จ๐ฐ ๐ญ๐จ ๐๐๐๐๐ ๐ง๐จ. ๐จ๐ ๐ฅ๐ข๐ง๐๐ฌ ๐ข๐ง ๐ ๐๐ข๐ฅ๐ ๐ข๐ง ๐๐ข๐ง๐ฎ๐ฑ?
Ans: wc -l file
๐๐จ๐ฐ ๐ญ๐จ ๐๐ก๐๐๐ค ๐ข๐ ๐ญ๐ฐ๐จ ๐๐ข๐ฅ๐๐ฌ ๐๐ซ๐ ๐ข๐๐๐ง๐ญ๐ข๐๐๐ฅ ๐จ๐ซ ๐ง๐จ๐ญ ๐ข๐ง ๐๐ข๐ง๐ฎ๐ฑ?
Ans: cmp fileA fileB
๐๐จ๐ฐ ๐ญ๐จ ๐๐จ๐ฆ๐ฉ๐๐ซ๐ ๐๐ง๐ ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ ๐๐ข๐๐๐๐ซ๐๐ง๐๐ ๐๐๐ญ๐ฐ๐๐๐ง ๐๐ข๐ฅ๐๐ฌ ๐ข๐ง ๐๐ข๐ง๐ฎ๐ฑ?
Ans: diff -u fileA fileB
๐๐จ๐ฐ ๐ญ๐จ ๐ซ๐๐๐จ๐ซ๐ ๐ฒ๐จ๐ฎ๐ซ ๐๐๐ญ๐ข๐ฏ๐ข๐ญ๐ฒ ๐จ๐ง ๐ญ๐๐ซ๐ฆ๐ข๐ง๐๐ฅ ๐ข๐ง ๐ ๐๐ข๐ฅ๐?
Ans: script
๐๐จ๐ฐ ๐ญ๐จ ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ ๐ฌ๐ญ๐๐ซ๐ญ๐ข๐ง๐ ๐ญ๐ฐ๐จ ๐๐ก๐๐ซ๐๐๐ญ๐๐ซ๐ฌ ๐จ๐ ๐๐ฅ๐ฅ ๐ฅ๐ข๐ง๐?
Ans: cut -c1-2 file.txt
๐๐จ๐ฐ ๐ญ๐จ ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ ๐ ๐ฌ๐ฉ๐๐๐ข๐๐ข๐ ๐ฅ๐ข๐ง๐ ๐๐ซ๐จ๐ฆ ๐ ๐๐ข๐ฅ๐?
Ans: sed -n '5p' file.txt
๐๐จ๐ฐ ๐ญ๐จ ๐ซ๐๐ฉ๐ฅ๐๐๐ ๐ ๐ฌ๐ฉ๐๐๐ข๐๐ข๐ ๐ฐ๐จ๐ซ๐ ๐ฐ๐ข๐ญ๐ก๐ข๐ง ๐ ๐๐ข๐ฅ๐?
Ans: sed -n 's/from/to/g' file.txt
๐๐จ๐ฐ ๐ญ๐จ ๐๐ฑ๐ญ๐๐ง๐ ๐ฌ๐ข๐ณ๐ ๐จ๐ ๐ ๐๐ข๐ฅ๐ ๐ฐ๐ข๐ญ๐ก๐จ๐ฎ๐ญ ๐๐๐๐ข๐ง๐ ๐๐ง๐ฒ ๐๐๐ญ๐?
Ans: truncate -s 100M file.txt
๐๐จ๐ฐ ๐ญ๐จ ๐๐ก๐๐๐ค ๐๐ฉ๐ฎ/๐๐จ๐ซ๐/๐ญ๐ก๐ซ๐๐๐ ๐ข๐ง๐๐จ ๐จ๐ ๐ฒ๐จ๐ฎ๐ซ ๐ฅ๐ข๐ง๐ฎ๐ฑ ๐ฌ๐๐ซ๐ฏ๐๐ซ?
Ans: lscpu