1. What are symbolic links?
Ans: Symbolic links (also known as soft links) are special files that act as pointers or references to other files or directories. They are similar to shortcuts in Windows. Creating a symbolic link does not create a duplicate of the target file but creates a link that points to the file’s location.
Creating a symbolic link:
ln -s /path/to/target /path/to/symlink
2. What is the difference between hard links and soft links?
Ans: A hard links and Soft link (symbolic links) are their mechanisms of referencing files (directly through inode for hard links vs. indirectly through path name for symbolic links), their behaviour when the target is deleted or moved, and their ability to reference files across different file systems.
Hard Link:
A hard link is a direct reference to the physical data on the disk. It is essentially an additional directory entry for a file, making it indistinguishable from the original file. Both the original file and the hard link share the same inode number and data blocks. Deleting one does not delete the data as long as one hard link still exists.
- A hard link is essentially another name for the same file. It points directly to the file’s inode (a data structure on a filesystem on Unix-like operating systems that stores all the information about a file except its name and its actual data).
- All hard links associated with a file have equal status; there’s no inherent distinction between the original file and its hard links.
- Deleting any hard link (including the original file) doesn’t affect the file’s data until all hard links are removed. The file’s data is only deleted once there are no more hard links pointing to it.
- Hard links cannot span across different file systems or partitions because they directly reference the inode.
sudo ln -f test.tx /home/ubuntu/new.txt
Soft Link:
A soft link (or symbolic link) is a file that points to another file or directory. Unlike hard links, soft links can span across different file systems and can link to directories. However, if the target file is deleted, the soft link becomes a dangling link that points to a non-existent file.
- A soft link, or symbolic link, is a separate file that points to the target file or directory using its path name. Unlike hard links, a symbolic link doesn’t point directly to the file’s inode but to its path.
- Symbolic links can reference files and directories across different file systems or partitions since they reference the file by its path name.
- If the target file is deleted or moved, the symbolic link becomes “dangling” and will no longer resolve to a valid file.
- Symbolic links can point to directories as well as files, whereas hard links can only point to files
sudo ln -s test.tx /home/ubuntu/new.txt
3. Explain the significance of the root
user in Linux?
Ans: The ‘root’ user is the superuser with administrative privileges. It has the highest level of access and can perform any operation on the system.
4. How do you find all files modified in the last 5 minutes in a directory and its sub-directories?
Ans: You can use the find
command in combination with the -mmin
option to search for files modified within the last 5 minutes in a directory and its sub directories. Here’s the command you can use:
find /path/to/directory -type f -mmin -5
Explanations:
find
: The command-line utility for searching files and directories./path/to/directory
: Replace this with the path to the directory where you want to start the search.-type f
: Specifies that only files should be considered (not directories-mmin -5
: Specifies the modification time of the file. “-5
” means modified within the last 5 minutes. If you want files modified exactly 5 minutes ago, you can use+4
instead.
5. What is a kernel in Linux?
Ans: kernel is the core component of the operating system. It acts as an intermediary between the hardware and the software, managing system resources, providing services to software applications, and enabling communication between different parts of the computer system.
6. Explain the purpose of the chmod
command?
Ans: It is used to change the permissions of files
and directories
. Its name stands for “change mode.” The permissions determine who can read, write, and execute a file or directory. chmod
allows users to modify these permissions according to their needs.
7. Explain the role of the grep
command in Linux?
Ans: The grep
command in Linux is a powerful tool used for searching text patterns within files or streams of data. Its name stands for Global Regular Expression Print
. grep
is widely used in command-line environments and scripts for tasks such as text processing, log file analysis, and pattern matching.
8. What is the purpose of the df
command?
Ans: The df
command in Linux is used to display information about the disk space usage on file systems. Its name stands for disk free
. The df
command provides a summary of available and used disk space for each mounted file system, including hard drives, partitions, and network file systems.
9. What is Linux?
Ans: Linux is an open-source operating system based on Unix, designed for flexibility, stability, and performance. It is widely used for servers, desktops, mobile devices, and embedded systems.
10. Who invented Linux? Explain the history of Linux.
Ans: Linux was created by Linus Torvalds in 1991 as a hobby project while he was a student at the University of Helsinki in Finland. He announced his project on the Usenet newsgroup comp.os.minix and released the first version (0.02) in October 1991. It quickly gained contributions from developers worldwide and grew into a robust, full-featured operating system kernel.
11. Explain the basic features of the Linux OS?
Ans: Below are some features of Linux:
- Open Source: Source code is freely available and can be modified.
- Multitasking: Can run multiple tasks simultaneously.
- Multiuser: Supports multiple users at the same time without interfering with each other.
- Security: Advanced security features including permissions, encryption, and firewalls.
- Portability: Can run on various hardware platforms.
- Shell: Powerful command-line interface for efficient system management.
- Networking: Strong networking capabilities, essential for server environments.
- Performance: Optimized for performance and reliability.
12. What is a Linux distribution? Name some popular Linux distributions?
Ans: A Linux distribution (distro) is a version of Linux that includes the Linux kernel and a selection of software packages to meet various needs.
Popular Linux distributions include:
- Ubuntu
- Fedora
- Debian
- CentOS
- Red Hat Enterprise Linux (RHEL)
- Arch Linux
- OpenSUSE
13. What is the Linux Kernel? Is it legal to edit Linux Kernel?
Ans: The Linux Kernel is the core part of the Linux operating system that manages hardware, system processes, memory, and peripheral devices. It is completely legal to edit the Linux Kernel because it is released under the GNU General Public License (GPL), which allows users to modify and distribute their versions.
14. What are the basic elements or components of Linux?
Ans: Below are the basic elements or components of linux:
- Kernel: Core of the operating system.
- Shell: Interface between the user and the kernel.
- File System: Organizes and stores files.
- System Libraries: Standard functions and libraries for system programs.
- System Utilities: Essential tools for system management and maintenance.
- Applications: User-level programs.
15. What is the major differences between Linux and Windows operating system?
Ans: Below are the difference between linux and windows
Feature | Linux | Windows |
---|---|---|
Source Code | Open source | Closed source |
Cost | Free (or very low cost) | Typically requires a license |
Customization | Highly Customizable | Limited customization |
User Interface | GNOME, KDE, XFCE, etc. | Mainly GUI (Windows Explorer) |
Security | Generally more secure | More susceptible to malware |
Usage | Servers, Desktops, Embedded Systems | Desktops, Gaming, Enterprise |
Support | Community-based, some commercial options | Commercial support from Microsoft |
16. Explain the difference between Unix and Linux?
Ans:
Feature | Unix | Linux |
---|---|---|
Source Code | Proprietary (some open-source variants) | Open source |
Cost | Often expensive | Free or very low cost |
Development | Developed by AT&T and various corporations | Developed by Linus Torvalds and community |
User Base | Mainly used in servers and workstations | Used in a wide range of devices |
Distributions | Various flavors (AIX, HP-UX, Solaris) | Multiple distributions (Ubuntu, Fedora) |
Hardware | Generally tied to specific hardware | Runs on a wide range of hardware |
17. How do users create a symbolic link in Linux?
Ans: Use the ln
command with the -s
option:
ln -s /path/to/original /path/to/link
18. What is the core of the Linux operating system?
Ans: The core of the Linux operating system is the Linux Kernel
.
19. Why is Linux regarded as a more secure operating system than other operating systems?
Ans: Linux is regarded as more secure due to:
- Open Source: Code can be audited by anyone.
- User Privileges: Strict user permissions limit access.
- Security Features: Built-in firewalls and SELinux/AppArmor.
- Less Targeted: Fewer malware attacks compared to more popular OS like Windows.
20. Elaborate all the file permissions in Linux
Ans: File permissions are represented by three categories: user (u), group (g), and others (o).
Each category has three types of permissions: read (r), write (w), and execute (x).
- Read (r): Allows viewing the contents.
- Write (w): Allows modifying the contents.
- Execute (x): Allows running the file as a program.
21. What is the Linux Kernel? Is it legal to edit it?
Ans: The Linux Kernel is the core component of the Linux operating system, responsible for managing system resources and hardware. Yes, it is legal to edit the Linux Kernel due to its open-source nature under the GNU General Public License (GPL).
22. Explain LILO?
Ans: LILO (Linux Loader) is a boot loader for Linux
. It loads the Linux operating system into memory and starts it. LILO can also be configured to boot other operating systems.
23. Write an command to check the number of files, disk space, and each user’s defined quota?
Ans:
To check disk space:
df -h
To check file count:
ls | wc -l
To check user quotas:
quota -u username
24. What is BASH?
Ans: BASH (Bourne Again SHell) is the default command interpreter on most Linux systems. It is a powerful shell that provides command-line editing, job control, and scripting capabilities.
25. Write a bash script to delete all the files in the current directory that contains the word linux
?
Ans:
#!/bin/bash
for file in *linux*; do
if [ -f "$file" ]; then
rm "$file"
fi
done
26. What is Virtual Desktop?
Ans: A Virtual Desktop allows users to have multiple desktop environments on a single physical machine, switching between them as needed.
27. Explain what shell scripts are and how they’re used in Linux.
Ans: Shell scripts are text files containing a sequence of commands for the shell to execute.
Shell script is used to do the below task:
- Automate repetitive tasks
- Simplify complex operations
- Manage system administration tasks.
28. What is advantages and disadvantages of open source?
Ans:
Advantages:
- Cost-effective
- Flexibility and Freedom
- Security through transparency
- Community support
Disadvantages:
- Potential lack of official support
- Varied documentation quality
- Compatibility issues
29. What is Shell in Linux?
Ans: The shell is a command-line interface that interprets and executes user commands. Examples include BASH, Zsh, and Ksh.
30. What is a root account?
Ans: The root account is the superuser account in Linux with unrestricted access to all commands and files on the system.
31. What is GUI?
Ans: GUI (Graphical User Interface) is a user interface that allows users to interact with the system through graphical elements like windows, icons, and buttons.
32. What is CLI?
Ans: CLI (Command-Line Interface) is a text-based interface where users interact with the system by typing commands.
33. What is the difference between CLI and GUI in Linux?
Ans:
Feature | CLI | GUI |
---|---|---|
Interface | Text-based | Graphical |
Resource Use | Lower | Higher |
Speed | Faster | Slower |
Complexity | Requires more knowledge | Easier to use |
Flexibility | Highly flexible and scriptable | Limited flexibility |
34. What is Swap Space?
Ans: Swap space is a portion of the hard drive used as virtual memory when the physical RAM is full.
35. What is the typical size for swap partitions under the Linux system?
Ans: The typical size for swap partitions is:
- 1.5 to 2 times the size of the RAM for systems with less than 4GB of RAM.
- Equal to the size of the RAM for systems with more than 4GB of RAM.
36. What is the difference between hard links and soft links?
Feature | Hard Links | Soft Links (Symbolic Links) |
---|---|---|
Inode | Same inode as the original file | Different inode |
Deletion | File remains if the original is deleted | Link breaks if the original is deleted |
Cross Filesystem | Cannot span filesystems | Can span filesystems |
Directory Linking | Cannot link directories | Can link directories (with options) |
37. What are the Standard streams?
Ans: Standard streams are:
- stdin (Standard Input): Input to the program (default is keyboard).
- stdout (Standard Output): Output from the program (default is screen).
- stderr (Standard Error): Error messages output (default is screen).
38. How to terminate a running process in Linux?
Use the kill
command followed by the process ID (PID):
kill <PID>
Or to forcefully terminate:
kill -9 <PID>
39. How to rename a file in Linux?
Ans:
Use the mv
command:
mv <old_file_name> <new_file_name>
40. How to write the output of a command to a file?
Ans: Use the >
redirection operator:
<code_command> > <output_file>
41. How to see the list of mounted devices on Linux?
Ans: Use the df
or mount
command:
df -h
or
mount
42. How to find where a file is stored in Linux?
Ans: Use the find
command:
find / -name filename
43. How to find the difference in two configuration files?
Ans: Use the diff
command:
diff file1.conf file2.conf
44. How to create a text file without opening it?
Ans: Use the touch
command:
touch filename.txt
45. How to delete a directory in Linux?
Ans: Use the rm
command with the -r
option:
rm -r directory_name
46. How do you mount and unmount filesystems in Linux?
Ans:
Mounting a filesystem:
1.Create a mount point if it doesn’t exist:
sudo mkdir /mnt/mount_point
2. Mount the filesystem:
sudo mount /dev/sdXn /mnt/mount_point
Replace /dev/sdXn
with your device identifier (e.g., /dev/sda1
).
Unmounting a filesystem:
1.Unmount the filesystem
sudo umount /mnt/mount_point
47. How do you troubleshoot network connectivity issues in Linux?
Ans:
1. Check the network interfsce units:
ip a
2. Verify IP configuration:
ip addr show
3. Check the connectivity with ping:
ping -c 4 google.com
4. check DNS resolution:
nslookup google.com
5. Check Routing Table:
ip route
6. Inspect Firewall:
sudo iptables -L
7. Examine Network Logs:
sudo dmesg | grep -i network
48. How do you list all the processes running in Linux?
Ans:
Use the ps
command:
ps aux
Or use top
or htop
for a dynamic real-time view:
top
htop
49. What is the chmod command in Linux, and how do you use it?
Ans: The chmod
command changes the file permissions.
Syntax:
chmod [permissions] [file]
Examples:
To give the owner read, write, and execute permissions, and others read and execute:
chmod 755 filename
To give everyone read and write permissions:
chmod 666 filename
50. What is the three standard streams in Linux?
Ans:
- stdin (Standard Input): Input stream, typically from the keyboard.
- stdout (Standard Output): Output stream, typically to the screen.
- stderr (Standard Error): Error output stream, typically to the screen.
51. How do you find the process ID (PID) of a running process?
Ans:
Use the pidof
or pgrep
command:
pidof process_name
pgrep process_name
52. What is the rsync command, and how do you use this command for synchronization?
Ans: The rsync
command synchronizes files and directories between two locations.
Syntax:
rsync [options] <source> <destination>
Example:
To synchronize a directory to a remote server:
rsync -avz /path/to/source/ user@remote:/path/to/destination
53. How do you create a user account?
Ans:
Use the useradd
command:
sudo useradd -m username
sudo passwd username
53. What are the best practices for user password security policies in Linux?
- Enforce strong passwords: Use a combination of letters, numbers, and special characters.
- Password aging: Require periodic password change.
sudo chage -M 90 username
- Account lockout policies: Lock accounts after several failed login attempts.
- Use shadow passwords: Ensure
/etc/shadow
is used for storing hashed passwords.
54. What are two types of Linux User Mode?
Ans:
- User Mode: Where applications and user processes run, with restricted access to system resources.
- Kernel Mode: Where the operating system kernel runs, with full access to hardware and system resources.
55. Which high-availability solutions can be used with Linux?
Ans:
- Heartbeat: Part of the Linux-HA project.
- Pacemaker: Cluster resource manager.
- DRBD: Distributed Replicated Block Device for real-time data replication.
- Keepalived: Provides load balancing and high availability.
56. How do you format a disk in Linux?
Ans:
1.Identify the Disk:
fdisk -l
2. Format the Disk:
sudo mkfs.ext4 /dev/sdx1
57. What is the Linux Shell? What types of Shells are there in Linux?
Ans: The Linux shell is a command-line interpreter that provides a user interface for the operating system.
Types of shells:
- BASH (Bourne Again SHell)
- Zsh (Z Shell)
- Ksh (Korn Shell)
- Tcsh (TENEX C Shell)
- Fish (Friendly Interactive Shell)
58. How do you change the password for a user account?
Ans: Use the passwd
command:
sudo passwd <username>
How can you enhance the security of the password file in Linux?
Ans:
- Use shadow passwords: Ensure
/etc/shadow
is used. - Restrict access: Limit access to the
/etc/shadow
file.
sudo chmod 600 /etc/shadow
sudo chown root:shadow /etc/shadow
59. What is the difference between a process and a thread?
Ans:
Feature | Process | Thread |
---|---|---|
Memory | Separate memory space | Shared memory space |
Creation | More resource-intensive | Less resource-intensive |
Communication | Inter-process communication needed | Direct communication |
Dependency | Processes are independent | Threads are dependent |
60. What is the ulimit command, and how do you use it?
Ans: The ulimit
command sets or reports user process resource limits.
Syntax:
ulimit [options] [limit]
Examples:
To view the current limits:
ulimit -a
To set the file size limit to 1000 MB
ulimit -f 1024
61. What is the find command, and how do you use it?
Ans: The find
command searches for files in a directory hierarchy.
Syntax:
find [path] [expression]
Examples:
To find all .txt
files:
find /path -name "*.txt"
62. What is RAID in Linux?
Ans: RAID (Redundant Array of Independent Disks) is a storage technology that combines multiple disk drives into a single logical unit for redundancy or performance improvement.
Types of RAID:
- RAID 0: Striping
- RAID 1: Mirroring
- RAID 5: Striping with parity
- RAID 6: Striping with double parity
- RAID 10: Combination of RAID 1 and RAID 0
63. What are the challenges of using Linux?
Ans:
- Learning Curve: Steeper learning curve for new users.
- Software Compatibility: Some proprietary software may not be available.
- Hardware Compatibility: Occasional issues with drivers for new hardware.
- Support: Limited official support, mostly community-driven.
64. What is a Zombie Process?
Ans: A zombie process is a process that has completed execution but still has an entry in the process table. It occurs when the process’s parent has not read its exit status.
65. What is the maximum length for a filename under Linux?
The maximum length for a filename under Linux is 255 bytes
.
66. What is the /proc file system?
Ans: The /proc
filesystem is a pseudo-filesystem that provides an interface to kernel data structures. It is commonly mounted at /proc
. The files within /proc
are not real files but virtual files; they contain runtime system information such as system memory, devices mounted, hardware configuration, etc.
67. How do you secure a Linux server?
Ans:
- Keep the system updated: Regularly apply security patches and updates.bashCopy code
sudo apt update && sudo apt upgrade
- Use strong passwords and change them regularly.
- Disable root login over SSH: Edit
/etc/ssh/sshd_config
and setPermitRootLogin no
. - Use SSH keys for authentication.
- Enable firewall: Use
iptables
orufw
to configure a firewall. - Disable unnecessary services:
sudo systemctl disable service_name
- Install and configure security tools: Tools like Fail2Ban, SELinux, or AppArmor.
- Monitor logs: Regularly check log files for unusual activity.
sudo tail -f /var/log/auth.log
68. What is the difference between BASH and DOS?
Ans:
Feature | BASH (Bourne Again SHell) | DOS (Disk Operating System) Command Line |
---|---|---|
System | Unix/Linux | MS-DOS/Windows |
Syntax | Case-sensitive | Case-insensitive |
Scripting | Supports powerful scripting with control structures | Limited scripting capabilities |
Pipes and Redirection | Extensive support | Limited support |
Environment | Rich set of environment variables | Basic set of environment variables |
Package Management | Package managers (apt, yum) | No built-in package management |
69. What is the strace
command?
Ans: The strace
command is a diagnostic, debugging, and instructional userspace utility for Linux. It is used to monitor the system calls and signals a program receives.
Example:
strace -o output.txt -e trace=open,read,write ls
70. How do you optimize Linux system performance?
Ans:
- Monitor system performance: Use tools like
top
,htop
,iotop
,sar
. - Optimize disk I/O: Use tools like
iostat
and tune filesystems. - Manage processes: Use
nice
,renice
,ionice
. - Optimize memory usage: Use
vmstat
,free
, and adjustswappiness
. - Network tuning: Adjust TCP parameters, use
ethtool
for NIC settings. - Service optimization: Disable unnecessary services and daemons.bashCopy code
sudo systemctl disable service_name
70. How to administer Linux servers?
Ans:
1.User Management: Add, delete, and modify users and groups
sudo useradd username
sudo usermod -aG groupname username
sudo passwd username
2. Package Management: Install, update, and remove software
sudo apt update
sudo apt install <package_name>
sudo apt remove <package_name>
3. Service Management: Start, stop, and enable/disable services.
sudo systemctl start <service_name>
sudo systemctl enable <service_name>
sudo systemctl stop <service_name>
sudo systemctl disable <service_name>
4. Security: Implement firewalls, monitor logs, and apply updates.
5. Backup and Recovery: Use tools like rsync
, tar
, and automate backups with cron jobs.
6. Monitoring: Use monitoring tools like Nagios, Zabbix, or Prometheus
71. What is a Linux virtual memory system?
Ans: The Linux virtual memory system allows the system to use more memory than physically available by using disk space (swap space) as an extension of RAM. It provides processes with a virtual address space and uses paging to load and unload pages to/from physical memory as needed.
72. What are process states in Linux?
Ans:
- Running (R): Executing on the CPU or waiting to be executed.
- Interruptible Sleep (S): Waiting for an event to complete.
- Uninterruptible Sleep (D): Waiting for I/O operation to complete.
- Stopped (T): Stopped by the user or a signal.
- Zombie (Z): Terminated but not yet reaped by its parent.
73. What command would you use to return a list of the open ports on a Linux server?
Ans: Use the netstat
or ss
command:
netstat:
netstat -tuln
ss:
ss -tulpn
74. What do you understand about process scheduling in Linux?
Ans: Linux uses a Completely Fair Scheduler (CFS) for process scheduling. It ensures fair distribution of CPU time among processes, prioritizing processes based on their nice value and ensuring that interactive processes get more CPU time. It uses time slices to schedule tasks, with lower nice values giving higher priority.
75. What are the most important Linux commands?
Ans: There are hundreds of commands used for Linux, some of them are as follows:
- File Management:
ls
,cp
,mv
,rm
,touch
,mkdir
- File Viewing:
cat
,less
,more
,head
,tail
- File Editing:
vi
,nano
- System Management:
top
,htop
,ps
,kill
,df
,du
- User Management:
useradd
,passwd
,usermod
,userdel
- Networking:
ifconfig
,ping
,netstat
,ss
- Package Management:
apt
,yum
76. What is the iptables
command, and how to use it for network filtering?
Ans: iptables
is a command-line utility for configuring Linux kernel firewall implemented within the netfilter
project.
Example:
Allow incoming SSH:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Block a specific IP address:
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
77. How do you troubleshoot a Linux OS that fails to boot?
Ans:
- Check bootloader configuration: Inspect
/boot/grub/grub.cfg
. - Use a live CD/USB: Boot into a live environment to access the system.
- Check system logs: Inspect
/var/log/boot.log
anddmesg
. - Reinstall the bootloader: Use
grub-install
to reinstall GRUB. - Repair filesystem errors:bashCopy code
fsck /dev/sdXn
- Check hardware issues: Ensure hardware components are functioning properly.
78. What is the init process in Linux?
Ans: The init
process is the first process started by the kernel during the booting process and is the ancestor of all other processes. It is responsible for initializing the system and spawning all other processes. Modern systems use systemd
, upstart
, or SysVinit
as the init
system.
79. What is SMTP?
Ans: SMTP (Simple Mail Transfer Protocol) is an Internet standard protocol for sending email messages between servers. It uses port 25 by default, with secure communication using ports 465 or 587.
80. What is LVM in Linux?
Ans: LVM (Logical Volume Manager) is a system for managing disk drives and other mass storage devices. It allows for flexible disk management, including resizing and moving partitions, and creating snapshots.
81. What is logical volume management (LVM), and what advantages does it offer?
Ans: LVM allows for the management of disk space more flexibly than traditional partitioning.
Advantages:
- Dynamic resizing: Resize logical volumes without unmounting.
- Snapshots: Create snapshots of volumes for backups.
- Flexible disk management: Combine multiple physical volumes into a single logical volume.
82. How to reduce or shrink the size of the LVM partition?
Ans:
1. Unmount the logical volume:
sudo umount /dev/mapper/vg_name-lv_name
2. Resize the filesystem:
sudo resize2fs /dev/mapper/vg_name-lv_name size
3. Reduce the logical volume:
sudo lvreduce -L size /dev/mapper/vg_name-lv_name
4. Resize the filesystem to fit the new size:
sudo resize2fs /dev/mapper/vg_name-lv_name
5. Mount the logical volume:
sudo mount /dev/mapper/vg_name-lv_name /mount_point
83. Which are the Linux Directory Commands?
Ans:
- List directory contents:
ls
- Change directory:
cd
- Make directories:
mkdir
- Remove directories:
rmdir
- Print working directory:
pwd
84. What is the difference between UDP and TCP?
Ans:
Feature | TCP (Transmission Control Protocol) | UDP (User Datagram Protocol) |
---|---|---|
Connection | Connection-oriented | Connectionless |
Reliability | Reliable | Unreliable |
Order | Ensures ordered delivery | No order guarantee |
Error Checking | Extensive error checking and recovery | Basic error checking |
Use Case | Web browsing, email, file transfer | Streaming, gaming, DNS queries |
85. What is the /etc/resolv.conf
file?
Ans: The /etc/resolv.conf
file is used to configure DNS servers for name resolution. It contains information on nameservers and search domain options.
Example:
nameserver 8.8.8.8
nameserver 8.8.4.4
86. Why /etc/resolv.conf and /etc/hosts files are used?
Ans:
- /etc/resolv.conf: Configures DNS servers for domain name resolution.
- /etc/hosts: Maps hostnames to IP addresses, used for local name resolution before querying DNS.
87. What is the difference between absolute and relative paths in Linux?
Ans:
Absolute path: Specifies the complete path from the root directory (/
)
/home/user/documents/file.txt
Relative path: Specifies the path relative to the current working directory.
documents/file.txt
88. What are daemons?
Ans: Daemons are background processes that start during booting or are initiated after login and provide various services. They typically run continuously and are not interactive.
89. How to check and verify the status of the bond interface?
Ans: Use the cat
command to view the bond interface status:
cat /proc/net/bonding/bond0
Replace bond0
with the appropriate bond interface name.
90. What is the advantages of Using NIC Teaming?
Ans:
- Increased Bandwidth: Combines multiple network interfaces to increase total bandwidth.
- Redundancy: Provides failover capabilities, ensuring network availability if one NIC fails.
- Load Balancing: Distributes network traffic across multiple NICs to optimize performance.
- Improved Throughput: Enhances data throughput by aggregating multiple network connections.
- Fault Tolerance: Maintains network connectivity even if one or more links are down.
91. What is network Bonding in Linux?
Ans: Network bonding refers to the process of combining multiple network interfaces (NICs) into a single logical “bonded” interface to increase throughput, provide redundancy, or both.
92. What is different Network Bonding Modes in Linux?
Ans:
- mode=0 (balance-rr): Round-robin policy for fault tolerance and load balancing.
- mode=1 (active-backup): Only one active slave, others are backup for fault tolerance.
- mode=2 (balance-xor): Transmit based on XOR of MAC addresses for load balancing and fault tolerance.
- mode=3 (broadcast): Transmit on all slaves for fault tolerance.
- mode=4 (802.3ad): Dynamic link aggregation using LACP for fault tolerance and load balancing.
- mode=5 (balance-tlb): Adaptive transmit load balancing.
- mode=6 (balance-alb): Adaptive load balancing with both transmit and receive load balancing.
93. What is different modes in VI Editor?
Ans: Below are the VI editor nodes used open and write the file.
- Normal Mode: For navigating and manipulating text.
- Insert Mode: For inserting and editing text.
- Visual Mode: For selecting and manipulating blocks of text.
- Command Mode: For executing commands to save, quit, search, etc.
94. Where is Shadow Passwords stored in Linux?
Ans: Shadow passwords are stored in the /etc/shadow
file, which contains encrypted user password information, improving security by restricting access to the passwords.
95. What are the ways to implementing Hardening and Security Policies in Linux?
Ans:
- Disable unused services: Prevent unnecessary services from running.
- Enforce strong passwords: Implement password policies and use tools like
pam_pwquality
. - Regular updates: Keep the system updated with security patches.
- Firewalls: Use
iptables
orufw
to control incoming and outgoing traffic. - Access Controls: Configure file permissions and use tools like
SELinux
orAppArmor
. - Auditing and Monitoring: Use tools like
auditd
andlogwatch
to monitor and log system activities. - SSH Security: Disable root login and use key-based authentication.
96. Which Daemon is used for scheduling commands in the linux?
Ans: The cron
daemon is used for scheduling commands to be executed at specified intervals.
97. What are the linux Shell and Its Types?
Ans: A shell is a command-line interpreter that provides a user interface for accessing the operating system’s services.
Types of Shells:
- Bash (Bourne Again SHell)
- Sh (Bourne Shell)
- Csh (C Shell)
- Ksh (Korn Shell)
- Zsh (Z Shell)
- Tcsh
98. How to extend volume group vG0 to 4 GB?
Ans:
1.Add new physical volume:
pvcreate /dev/sdx
2. Extend the volume group
sudo vgextend VG0 /dev/sdX
3. Extend the logical volume if needed:
sudo lvextend -L+4G /dev/VG0/lv_name
99. What is ssh and how ssh can connect to a Remote Server?
Ans: SSH (Secure Shell) is a protocol for securely accessing network services over an unsecured network.
Connect to a remote server:
ssh -i ~/.ssh/id_rsa username@hostname_or_ip_address
100. How to open a File in Read-Only Mode Using Vim Editor?
Ans:
vim -R filename
101. How to search for a Specific Employee ID in a File Using Vim Editor?
Ans:
1. Open the file
vim <filename>
2. Enter Search mode and type the Employee ID
# press / and type EmployeeID
102. How to Jump to a Particular Line in a File Using Vim Editor?
Ans:
1.Open the file
vim <filename>
2. Enter the line no:
:24
103. What are environmental variables?
Ans: Environmental variables are dynamic values that affect the processes or programs on a computer. Examples include PATH
, HOME
, and USER
.
104. How to sort entries in a Text File in Ascending Order?
Ans:
sort filename
105. What is Environment Variables vs Shell Variables in Linux?
Ans:
- Environment Variables: Available to any child process of the shell, typically set in shell initialization files.
- Shell Variables: Only available in the current shell session.
106. What are the key benefits of Scripting on Linux?
Ans:
- Automation: Automate repetitive tasks to save time.
- Efficiency: Scripts can perform tasks more quickly and consistently than manual commands.
- Customization: Create custom scripts tailored to specific needs.
- Reusability: Write scripts once and reuse them across different projects or systems.
- Complex Tasks: Handle complex tasks that involve multiple commands and conditions.
107. Name default ports used for DNS, SMTP, FTP, SSH, DHCP, and Squid?
Ans:
- DNS (Domain Name System): 53
- SMTP (Simple Mail Transfer Protocol): 25
- FTP (File Transfer Protocol): 21 (command), 20 (data)
- SSH (Secure Shell): 22
- DHCP (Dynamic Host Configuration Protocol): 67 (server), 68 (client)
- Squid (Proxy Server): 3128 (default), 8080 (alternative)
108. Explain Process Management System Calls in Linux?
Ans: Process management system calls in Linux include:
- fork(): Creates a new process by duplicating the current process.
- exec(): Replaces the current process image with a new process image.
- wait(): Waits for a child process to change state.
- exit(): Terminates the current process.
- getpid(): Returns the process ID of the calling process.
- kill(): Sends a signal to a process.
109. What is the grep
command used for in Linux?
Ans: The grep
command searches through files for lines that match a specified pattern.
For example:
grep 'pattern' filename
To search recursively through directories:
grep -r 'pattern' /path/to/directory
110. What is a daemon in Linux programming?
Ans: A daemon is a background process that runs continuously and handles requests for services such as logging, printing, and networking. It is often started at boot time and runs continuously without user interaction.
111. What is an array in Linux shell scripting? Give an example
Ans: An array in shell scripting is a collection of elements stored under a single variable name.
# Declare an array
my_array=("value1" "value2" "value3")
# Access array elements
echo ${my_array[0]} # Outputs: value1
echo ${my_array[1]} # Outputs: value2
# Iterate through an array
for element in "${my_array[@]}"; do
echo $element
done
112. What are the process states in Linux?
Ans:
- Running (R): Process is either running or ready to run.
- Sleeping (S): Process is waiting for an event to complete.
- Stopped (T): Process has been stopped, usually by a signal.
- Zombie (Z): Process has completed execution but still has an entry in the process table.
113. What is the export
command used for?
Ans: The export
command sets environment variables, making them available to child processes.
export VAR_NAME=value
To check the value of the variable:
echo $VAR_NAME
114. What is redirection?
Ans: Redirection is the process of directing the output/input of a command to/from a file or another command.
1.>: Redirects standard output to a file, overwriting the file if it exists.
command > file
2. >>:Appends standard output to a file:
command >> file
3. < : Redirects standard input from a file.
command < file
4. 2>: Redirects standard error to a file.
command 2> file
5. &>: Redirects both standard output and standard error to a file.
command &> file
For example:
command > output.txt 2>&1
115. Why is the tar
command used?
Ans: The tar
command (short for “tape archive”) is used in Unix and Unix-like operating systems to create, maintain, modify, and extract files from an archive file (commonly known as a tarball). Tarballs are typically used for:
- Backup: Archiving files and directories for backup purposes.
- Distribution: Combining multiple files and directories into a single file for easier distribution.
- Compression: Often used with compression utilities like
gzip
orbzip2
to reduce the size of the archive.
For Example:
Create an archive: tar -cvf archive.tar /path/to/directory
Extract an archive: tar -xvf archive.tar
Create a compressed archive: tar -czvf archive.tar.gz /path/to/directory
Extract a compressed archive: tar -xzvf archive.tar.gz
116. What is a Latch?
Ans: A latch is a type of digital storage device that holds one bit of information. It is a basic building block in digital electronics used to store state information. Latches are typically used in:
- Memory storage: Storing data temporarily.
- State machines: Holding the current state.
- Synchronizing: Ensuring data stability in circuits.
Latches are level-triggered, meaning they change state when a control signal (enable or clock) is at a particular level.
117. Explain Regular Expressions and Grep?
Ans: Regular Expressions
(regex) are patterns used to match character combinations in strings. They are utilized for searching, manipulating, and parsing text based on specific patterns.
grep
(global regular expression print) is a command-line utility in Unix/Linux used for searching plain-text data sets for lines that match a regular expression. It is commonly used for:
- Text search: Finding text within files.
- Filtering: Displaying lines that match a pattern.
- Log analysis: Extracting relevant information from log files.
118. What is the minimum number of disk partitions required to install Linux?
Ans: The minimum number of disk partitions required to install Linux is typically one. This is the root (/) partition, which contains the entire file system. However, it is common practice to have at least two partitions:
Root (/) partition: Contains the operating system and all user files.
Swap partition: Used for swapping pages of memory to disk when RAM is full.
119. What are inode and process id?
Ans: Inode (Index Node):An inode is a data structure on a filesystem that stores information about a file or a directory, except its name and its actual data.
Fields stored in an inode include:
- File type (e.g., regular file, directory)
- Permissions (e.g., read, write, execute)
- Owner and group ID
- Size of the file
- Timestamps (creation, modification, access times)
- Number of links (references) to the file
- Pointers to the data blocks on disk
Process ID (PID): A process ID is a unique identifier assigned by the operating system to each running process. It is used to manage and track processes within the system.
120. What is the purpose of the ps
command in Linux? How would you use it in a real-world setting?
Ans: The ps
command in Linux is used to display information about the currently running processes. It can provide details such as process IDs, user IDs, CPU usage, memory usage, and command names.
Common usages include:
1.Display all running processes: ps -e
or ps -aux
2. Display processes for a specific user: ps -u username
3. Display detailed information for all processes: ps -ef
121. What command would you use to check the amount of available disk space on a Linux system?
Ans: Use the df
command:
df -h
The -h
option provides the output in a human-readable format (e.g., KB, MB, GB).
122. How do you check the status of a service or daemon in Linux?
Ans: Use the systemctl
command:
systemctl status <service_name>
123. How do you check the status of all the services?
Ans: Use the systemctl
command to list all services and their statuses:
systemctl list-units --type=service
124. How do you compress and decompress files in Linux?
Ans:
To compress files, use gzip
or bzip2
:
gzip filename
bzip2 filename
To decompress files, use gunzip
or bunzip2
:
gunzip filename.gz
bunzip2 filename.bz2
125. What is the difference between /etc/passwd and /etc/shadow files?
Ans:
/etc/passwd
: Contains user account information such as usernames, user IDs (UIDs), group IDs (GIDs), home directories, and login shells. Passwords are not stored here in modern systems.
/etc/shadow
: Contains encrypted user password information along with password expiration data. Access to this file is restricted to enhance security.
126. What is the difference between a process and a daemon in Linux?
Ans:
Process: A running instance of a program that can be in the foreground or background.
Daemon: A background process that starts at boot time or when needed, performing specific tasks or waiting for requests.
127. What is the difference between a process and a thread in Linux?
Ans:
Process: An independent execution unit with its own memory space.
Thread: A smaller execution unit within a process that shares the process’s memory space. Threads within the same process can communicate more efficiently but are less isolated than processes.
128. How would you schedule a task in Linux?
Ans: Use the at
command to schedule a one-time task:
echo "command" | at time
Example:
echo "backup.sh" | at 02:00
129. How do you schedule recurring tasks in Linux?
Ans:
Use cron
jobs to schedule recurring tasks. Edit the crontab file using:
crontab -e
Add a line in the following format to schedule a task:
* * * * * /path/to/command
Where the five asterisks represent the minute
, hour
, day of the month
, month
, and day of the week
, respectively.
130. What is the sed
command used for in Linux?
Ans: The sed
(stream editor) command is used for performing basic text transformations on an input stream (a file or input from a pipeline).
Example:
sed 's/old-text/new-text/g' filename
This replaces all occurrences of old-text
with new-text
in the file filename
.
131. What are runlevels in Linux?
Ans: Runlevels are a legacy concept in Unix-based systems that define the state of the machine, describing what services and processes are running. Common runlevels include:
0
: Halt1
: Single-user mode3
: Multi-user mode without graphical interface5
: Multi-user mode with graphical interface6
: Reboot
132. What command can you use to make a tape archive file of /home directory and send it to the /dev/tape device?
Ans: Use the tar
command:
tar -cvf /dev/tape /home
133. Explain how you would search a directory and its subdirectories to find all files that have been modified in the last 30 minutes?
Ans:
Use the find
command:
find /path/to/directory -type f -mmin -30
134. What is sudo
in Linux?
Ans: sudo
(superuser do) allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. It is commonly used to perform administrative tasks with root privileges.
Example:
sudo apt-get update
135. Explain how you would find the five largest files in a directory and all its subdirectories?
Ans: Use the find
and sort
commands together with du
to find the largest files:
find /path/to/directory -type f -exec du -h {} + | sort -rh | head -n 5
This command finds all files, displays their sizes, sorts them by size in descending order, and shows the top five.
136. What is umask
?
Ans: umask
(user file-creation mode mask) determines the default permission settings for newly created files and directories. It sets the default permissions by subtracting the umask
value from the system’s default permissions (usually 666 for files and 777 for directories).
137. How to find and kill a process in Linux?
Ans:
To find a process, use the ps
or pgrep
commands:
ps aux | grep process_name
pgrep -l process_name
To kill a process, use the kill
command with the process ID (PID):
kill -9 PID
138. What is SELinux?
Ans: Security-Enhanced Linux (SELinux) is a security module that provides a mechanism for supporting access control security policies. It enforces mandatory access control (MAC) policies to confine user programs and system services.
139. What is the purpose of the SSH protocol in Linux, and how do you securely connect to a remote server using SSH?
Ans:
The SSH (Secure Shell) protocol provides a secure way to access and manage remote servers over an unsecured network. To connect to a remote server:
ssh username@remote_host
140. How do you check the contents of a file without opening it in Linux?
Ans:
Use commands like cat
, more
, less
, head
, or tail
:
cat filename
more filename
less filename
head filename
tail filename
141. How to identify which shell you are using?
Ans: Use the echo
command to check the $SHELL
environment variable
echo $SHELL
142. How do you look at the contents of a file named sample.z
?
Ans:
First, decompress the file using uncompress
or zcat
:
zcat sample.z | less
143. What is the difference between cron
and anacron
?
Ans:
cron
: Schedules recurring tasks to run at specific times or intervals. Assumes the system is always running.
anacron
: Used for running commands periodically with a frequency specified in days. It does not assume the system is always running and can execute missed jobs when the system starts up.
144. What is the purpose of the crontab file in Linux, and how do you schedule recurring tasks using cron jobs?
Ans:
The crontab
file defines the schedule for recurring tasks using the cron
daemon. Edit the crontab file with:
crontab -e
Add a line with the schedule and command:
* * * * * /path/to/command
145. What does the cron
command do in Linux? How can you use it to schedule tasks?
Ans: The cron
command schedules tasks to run at specific times or intervals. Use crontab -e
to edit the schedule, specifying the time and command.
146. Explain how you would recursively delete all empty directories in a specified path?
Ans:
Use the find
command to find and delete empty directories:
find /path/to/directory -type d -empty -delete
147. How do you find and replace text in a file using the sed
command in Linux?
Ans:
Use sed
to find and replace text:
sed -i 's/old-text/new-text/g' filename
The -i
option edits the file in place.
148. What is the purpose of the sudoers file in Linux, and how do you configure sudo access for users?
Ans: The sudoers
file defines the permissions for users to execute commands as the superuser or another user. Edit the file using visudo
:
visudo
Add a line to grant a user access:
username ALL=(ALL) ALL
149. How do you change the ownership of a file or directory in Linux using the chown
command?
Ans:
Use the chown
command to change ownership:
chown user:group filename
Replace user
and group
with the new owner and group.
150. What is the purpose of the ping
command in Linux, and how do you test network connectivity to a remote host?
Ans: The ping
command checks network connectivity to a remote host by sending ICMP echo requests and measuring response times:
ping 18.222.42.11
151. How do you recursively copy files and directories in Linux using the cp
command?
Ans: Use the cp
command with the -r
option to copy recursively
cp -r /source/directory /destination/directory
151. What is the purpose of the netstat
command in Linux, and how do you view network connections and listening ports?
Ans: The netstat
command displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. View network connections and listening ports with:
netstat -tulpn
152. How to copy a file to multiple directories in Linux?
Ans: Use a loop to copy the file to multiple directories:
for dir in /path/to/dir1 /path/to/dir2 /path/to/dir3; do
cp /path/to/file "$dir"
done
153. How are files organized in Linux?
Ans: Files in Linux are organized in a hierarchical directory structure starting from the root directory (/
). This structure resembles an inverted tree, with the root directory at the top and branches representing subdirectories and files. Key directories include:
/bin
: Essential command binaries./boot
: Bootloader files./dev
: Device files./etc
: System configuration files./home
: User home directories./lib
: Essential shared libraries./media
: Mount points for removable media./mnt
: Temporary mount points./opt
: Optional software packages./proc
: Process and system information./root
: Home directory for the root user./sbin
: System binaries./tmp
: Temporary files./usr
: User programs and utilities.
154. How can you find the IP address of a Linux system?
Ans: You can find the IP address of a Linux system using several commands
1.Using ifconfig
(deprecated but still used in some distributions):
ifconfig
Using ip
(recommended):
ip addr show
Using hostname
:
hostname -I