Linux
Linux
1. What is Linux?
There are various Linux distros but the following are the most commonly used:
Ubuntu
Debian
CentOS
Fedora
RedHat
Ubuntu is free and open-source, which means it is free to use, modify, and distribute. It provides
a user-friendly and intuitive interface, making it easy to navigate and use, even for users who
are new to Linux. Ubuntu supports a wide range of software applications, with a large software
repository with thousands of free and open-source programs available for installation. It is
known for its strong security features, with regular security updates and a strong community
focus on keeping Ubuntu secure. Ubuntu is designed to be stable and reliable, offering better
performance and efficiency compared to some other operating systems, especially on older
hardware.
4. What are the major differences between Linux and Windows?
Comparison
Factor Linux Windows
It is a free and
It is not open-source and is free to
Free/Paid open-source
use.
OS.
As a path
separator, it Windows uses a backward slash
Path separator
uses a forward between the directories.
slash.
Linux is more
Efficiency efficient than Windows is less efficient.
Windows.
It uses a
Kernel type monolithic It uses a microkernel.
kernel.
Linux file
File system systems are Its file system is case-insensitive.
case-sensitive.
5. Define the basic components of Linux.
8. Explain LILO
LILO, i.e., Linux Loader and is a Linux Boot loader. It loads the Linux
operating system into memory and starts the execution. Most operating
systems like Windows and macOS come with a bootloader. While in
Linux, you need to install a separate boot loader, and LILO is one of the
Linux boot loaders.
9. What is Shell in Linux?
A shell is a special user program that provides an interface for the user to use
operating system services. Shell accepts human-readable commands from users and
converts them into something which the kernel can understand. It is a command
language interpreter that executes commands read from input devices such as
keyboards or from files. The shell gets started when the user logs in or starts the
terminal
The root is like the user’s name or system administrator account in Linux.
The root account provides complete system control, which an ordinary
user cannot do.
CLI, i.e., command line interface. It takes input as a command and runs
the tasks of the system. The term GUI refers to the Graphical User
Interface or the human-computer interface. It uses icons, images, menus,
and windows, which can be manipulated through the mouse.
Linux uses swap space to expand RAM. Linux uses this extra space to
hold concurrently running programs temporarily.
13. What is the difference between hard links and soft links?
Here is the table that shows the difference between soft links and hard links:
Hard Links Soft Links
It includes original
It includes the original file location.
content.
There is no relative
Relative paths are used for soft links.
path for hard links.
Symbolic links, symlink, or soft links are shortcuts to files and directories.
Users can create the symbolic link in Linux through the’ ln’ command.
The general command to create a symbolic link is as follows:
ln -s <existing_source file> <optional_symbolic link>
Output and input in Linux OS are divided into three standard streams:
Stdin (standard input)
stdout(standard output)
stderr (standard error)
Under Linux, these standard streams channel communication of output
and input between programs and their environment.
In this case, you can use the ‘mount’ and ‘umount’ commands.
For mounting:
First, identify the partition through the fdisk -l command. You can also
use the lsblk command for it.
After identifying the partition, create the directory which will work as
the mount point. For example, running the mkdir /mnt/mountpnt will
create the mountpnt directory as the mount point.
Finally, you can run sudo mount <partition> <mount_point_directory>
to complete the mounting.
For Unmounting:
Once you check if the specific filesystem is in use, you can run the `sudo
umount <mount_point_directory>` for unmounting. If you want to learn
more about the mount command in Linux, check out this brief guide.
17. How do you troubleshoot network connectivity issues in Linux?
There are multiple ways to troubleshoot the network connectivity and find
the issue correctly:
You can list the currently running process in Linux through various commands
such as:
ps Command:
The ps command displays brief information about the running processes.
You can use the ps -f or ps -f command because the -f option shows the full-
format result, and the -e option displays all processes. Moreover, you can use
the ps auxf command to get a detailed list of processes.
You can use the chmod command to change the file permissions of
the directories. It offers a simple way to control the read and write permissions.
For instance, if you want to change the permission of the ABC.sh script and
give it the write and executable permission .
You can use the chmod command to change the file permissions of the
directories. It offers a simple way to control the read
20. How do you check disk space usage?
There are some simple commands you can use to check disk space usage,
such as:
df Command:
The df or disk-free command shows the used and the available disk
space. You can use the additional options to check disk space differently. For
instance, you can use the df -h command to check the disk usage in the
human-readable format.
du Command:
The du or disk usage command estimates and shows the disk space
usage, so running the du command with no option shows the disk usage of
your current directory. However, you can run the following command to check
the disk usage of a specific directory:
du -sh ~/<directory>
ncdu Command:
The NCurses Disk Usage, or ncdu command, displays more interactive
disk usage. Similar to the du command, the ncdu command also requires the
path of the specific directory to check its space.
ps Command:
ps command not only displays the currently running process but also
shows the process’s PID. However, if you want to check the PID of a specific
process, you can combine the ps with the grep command:
ps -e | grep -i <process_1>
22. What is the rsync command, and how do you use this command for
synchronization?
The rsync command is used to synchronize and transfer the files in Linux. It
synchronizes files between two local systems, directories, or a network.
The basic rsync command contains the following:
rsync <options> <source> <destination>
For example, let’s synchronize between Documents and the Downloads
directory. For this, you need to run the following command:
rsync -av ~/Documents ~/Downloads
If you want to go one step further, then you can use the below command:
rsync -avz --delete ~/Documents ~/Downloads
In the above command:
The -a option preserves all the permissions and other attributes
The -v option displays the detailed output of the synchronization
The -z allows compression that decreases the bandwidth use.
The –delete option removes the file in the Downloads that do not exist in
the Documents directory.
You can use adduser and useradd commands to create a user for the system.
useradd Command:
Let’s create a username, “Ron,” and provide a password for accessing the
system:
useradd Ron
passwd Ron
You can also explore the useradd command’s additional options to modify the
new user’s permissions and privileges.
adduser Command:
The mkfs or make file system command helps format the disk in the Linux
system. All you need to do is use the following method to format the disk:
First, run the lsblk command to list the available partitions and identify which
disk you want to format.
If the selected disk is mounted, then unmount it through the following
command:
umount <partition>
Now, find the file system type of the disk, like EXT4, NTFS, or XFS. Once you
are done then, run one of the following commands according to the file system
type:
mkfs.ext4 <partition>
mkfs.xfs <partition>
mkfs.ntfs <partition>
Finally, mount the disk again through the mount command after the successful
format. Moreover, please ensure that you have created a complete disk backup
to eliminate the chances of data loss.
Changing the password of a user account is simple because all you need to do
is use the passwd command:
passwd username
For example, let’s change the password of a user “Ron” through the below
command:
passwd Ron
Once you run the command, the system will ask you to enter and confirm the
new password.
26. What is the difference between a process and a thread?
In Linux, processes are the independent program, while a thread is the unit of
execution. So here are the complete differences between process and thread:
Comparison
Factors Process Thread
Creation time
Creation time Creation time is less.
is higher
It is
independent It depends on other threads because
Dependency because it they share some memory with other
does not share threads.
memory.
Resource use
Resource Requires lesser resources
is higher
The
Termination
termination The termination time is less.
time
time is higher
27. What is the ulimit command, and how do you use it?
The ulimit command controls the resource limit for the user process. You
can use the ulimit command to set the limit on the system resource to prevent
consuming the higher resources. This command contains multiple options to
set the limit. For example, you can use the u option to set a maximum number
of processes to 50:
ulimit -u 50
You can explore more options of the ulimit command by following this guide.
28. What is the find command, and how do you use it?
/proc (Proc File System) is the virtual file system that shows information about
the system and the Kernel data structures. It is the essential interface to
access the system, perform debugging tasks, check the Kernel functioning, find
process-related information, and many more.
Therefore, you can use /proc file system in Linux to get information about the
system and modify the particular Kernel parameters at the runtime.
There are multiple methods to secure the Linux server and protect it from data
breaches, security threats, and unauthorized access. Here are some of these
methods:
Create a strong password
Update the server and apply security patches.
Use secured protocols like SSH and configure it to use key-based
authentication for higher security.
Use the intrusion detection system (IDS) to monitor network traffic and
prevent malicious activities.
Configure the firewall to limit the inbound and outbound traffic on the server.
Disable all unused network services.
Create regular backups.
Review logs and perform regular security audits.
Encrypt network traffic and enable monitoring.
33. What is strace command?
The strace command is the diagnostic utility by which you can trace and
monitor the system calls generated by the process. It allows you to find how
programs interact with Kernel and can be used for debugging and
troubleshooting. For example, let’s find the system calls generated by the ls
command:
strace ls
Once you run the above command, the system will start tracing the list
command and show the system calls generated by it. Output from the above
command includes information like call name, argument, and return values.
34. How do you optimize Linux system performance?
You can optimize the Linux performance through various strategies to improve
resource usage and efficiency. So some of the strategies are:
Updates the system as per the latest one available.
Optimize the disk, enable the caching, and optimize the access pattern.
Manage memory and CPU usage.
Disable the necessary services and use lightweight alternatives of the
tools.
Monitor the system resources regularly.
Perform the Kernel parameter tune-up.
Use tools like Performance Co-Pilot (PCP) to monitor system-level
performance.
There are a ton of useful commands in Linux, and here are some of the
commonly used commands:
ls: Display directory contents such as folders and files.
mkdir: Used to create a new directory.
pwd: Shows the current directory.
top: Display system running processes and resource usage.
grep: Search a specific pattern in a file.
cat: Through this command, users can add multiple files and also display the
content of the files.
tar: Archives directories and files into a tarball.
wget: Download files from the browser or web.
free: Shows memory usage.
df: Shows disk space usage.
man: Gives a manual page for a specific command that displays instructions
and details.
39. What is the iptables command, and how to use it for network filtering?
In case of the system boot failure, you can follow various approaches
such as:
Check the warning and error messages you get during the boot
process because it can help you diagnose the issues.
Check the boot logs to find the exact reason behind the boot error.
Open the GRUB bootloader and check the boot options to solve the
booting problems.
Check the hardware connections like cables, RAM, cooling fan, etc.
If the system shows an error message related to the Kernel, try to
boot it with the older Kernel version from GRUB.
Identify the last changes you made in the system before the boot.
The init or also called the initialization process is the first process that
begins during the system boot. It is responsible for initializing and
processing the system in its functional state. Hence, init works as the parent
process because its process ID is 1. Originally Linux systems used to have
SysV init, but now it is developed as the systemd init (an improved version of
SysV).
42. What is SMTP?
SMTP stands for Simple Mail Transfer Protocol. This set of communication
guidelines allows the software to transmit electronic mail online. The main aim
of SMTP is to set communication rules between servers. There are two models
of SMTP:
End-to-end model: This model is used to connect different organizations.
Store-and-forward model: This model is used within an organization.
The following table shows the difference between UDP and TCP:
Factors UDP TCP
Video/voice
conferencing,
DNS, online File transfers, email, web browsing,
Applications
gaming, database transactions, etc.
streaming
media, etc.
The /etc/resolv.conf is the config file used for the DNS server resolution
process. This config file is used to specify the DNS server, set up the search
directive for domains, and configure the resolver options.
46. What is the difference between absolute and relative paths in Linux?
Absolute path = It specifies the exact location of a file or directory from the root
directory (“/”). We will notice that they always start with a forward slash (“/”).
For Example: `/home/user/jayesh/geeksforgeeks.txt`
Relative paths = It specifies the location relative to the current working
directory. In this we do not start with a forward slash (“/”).
For Example: `documents/file.txt`
The grep command is used to search for specific patterns within files or input
streams. It allows us to find and print lines that we give to match the pattern.
For example: If we want to search `test` in a text file name “file.txt”. We use
the following command
grep "test" file.txt
This command will search for the word `test` in the file named “file.txt” and print
the matching lines.
To compress files in Linux, you can use the tar command along with gzip
compression.
For example: If we want to create a file name “jayesh” with gzip compression.
We use the following command.
tar -czvf jayesh.tar.gz files
This command will create a compressed archive file containg the specified
“files”
To decompress the same, we use the following command.
tar -xzvf jayesh.tar.gz
Network connectivity between two Linux systems can be checked using tools
like ‘ping’ or ‘traceroute’, which send packets to the target system and report on
the round-trip time and the path taken.