0% found this document useful (0 votes)
48 views

Linux 100 Interview Questions

Uploaded by

krishnakarthika
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Linux 100 Interview Questions

Uploaded by

krishnakarthika
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

DevOps Shack

LINUX 100 Interview Questions


Click Here To Enrol To Batch-5 | DevOps & Cloud DevOps

1. What is Linux?
• Answer: Linux is a free, open-source operating system based on Unix. It was created
by Linus Torvalds in 1991 and is widely used in servers, desktops, and embedded
systems.
• Command: uname -a (displays system information)

2. What is the Linux kernel?


• Answer: The Linux kernel is the core part of the Linux operating system that manages
hardware resources and provides essential services to other software.
• Command: uname -r (displays kernel version)

3. Explain the directory structure in Linux.


• Answer: The Linux directory structure follows a hierarchical format with root (/) at the
base. Important directories include /bin (binary executables), /etc (configuration
files), /home (user home directories), /var (variable data files), /usr (user programs),
and /tmp (temporary files).
• Command: ls /

4. How do you check the current working directory?


• Answer: You can check the current working directory using the pwd (print working
directory) command.
• Command: pwd
5. How do you list files in a directory?
• Answer: The ls command lists files in a directory. Adding options like -l provides a
detailed list, and -a includes hidden files.
• Command: ls -la

6. How do you change file permissions?


• Answer: The chmod command changes file permissions. Use symbolic (e.g., chmod
u+x file) or numeric (e.g., chmod 755 file) modes.
• Command: chmod 755 filename

7. How do you change file ownership?


• Answer: The chown command changes file ownership. The format is chown
owner:group filename.
• Command: chown user:group filename

8. What is the purpose of the sudo command?


• Answer: The sudo command allows a permitted user to execute a command as the
superuser or another user, as specified by the security policy.
• Command: sudo command

9. How do you view the contents of a file?


• Answer: You can use commands like cat, more, less, head, and tail to view file
contents.
• Command: cat filename, less filename, head filename

10. How do you search for a file in Linux?


• Answer: The find command searches for files in a directory hierarchy.
• Command: find /path -name filename

11. What is the difference between grep and egrep?


• Answer: grep searches for patterns in files, while egrep (extended grep) supports
extended regular expressions.
• Command: grep pattern filename, egrep pattern filename
12. How do you compress files in Linux?
• Answer: Use commands like gzip, bzip2, and zip to compress files.
• Command: gzip filename, zip archive.zip filename

13. How do you uncompress files in Linux?


• Answer: Use commands like gunzip, bunzip2, and unzip to uncompress files.
• Command: gunzip filename.gz, unzip archive.zip

14. What is a symbolic link?


• Answer: A symbolic link is a file that points to another file or directory. It’s created
using the ln -s command.
• Command: ln -s target linkname

15. How do you display disk usage?


• Answer: The df command displays disk space usage, and du shows disk usage of
files and directories.
• Command: df -h, du -sh directory

16. How do you check memory usage?


• Answer: The free command displays memory usage, and top provides a dynamic
view of system processes and memory usage.
• Command: free -h, top

17. What is a process in Linux?


• Answer: A process is an instance of a running program. Linux manages processes
through process IDs (PIDs).
• Command: ps, top

18. How do you list running processes?


• Answer: The ps command lists running processes. Use ps aux for a detailed list.
• Command: ps aux

19. How do you terminate a process?


• Answer: Use the kill command followed by the process ID (PID). kill -9
PID forcefully terminates a process.
• Command: kill PID, kill -9 PID

20. How do you change the priority of a process?


• Answer: The nice command starts a process with a specified priority,
and renice changes the priority of an existing process.
• Command: nice -n priority command, renice priority PID

21. What is a daemon in Linux?


• Answer: A daemon is a background process that runs continuously and performs
specific operations, often started at boot time.
• Example Daemon: sshd (Secure Shell Daemon)

22. How do you check open ports on a system?


• Answer: The netstat and ss commands display network connections and listening
ports.
• Command: netstat -tuln, ss -tuln

23. How do you set environment variables?


• Answer: Use the export command to set environment variables.
• Command: export VAR=value

24. How do you view environment variables?


• Answer: The printenv or env commands display environment variables.
• Command: printenv, env

25. How do you schedule tasks in Linux?


• Answer: Use cron for scheduling recurring tasks and at for one-time tasks.
• Command: crontab -e, at time

26. What is the difference between cron and anacron?


• Answer: cron schedules tasks based on precise times, while anacron is used for
periodic tasks that are not time-sensitive and can run at any time after a system is
back online.
• Command: crontab -e, anacrontab
27. How do you display the last login information?
• Answer: The last command displays the last login information for users.
• Command: last

28. How do you find the location of an executable?


• Answer: Use the which command to find the location of an executable in the
system’s PATH.
• Command: which executable

29. How do you count the number of lines, words, and


characters in a file?
• Answer: The wc command counts lines, words, and characters in a file.
• Command: wc filename

30. How do you display the first and last few lines of a file?
• Answer: Use the head command to display the first few lines and the tail command
to display the last few lines of a file.
• Command: head filename, tail filename

31. How do you create a new user in Linux?


• Answer: The useradd command creates a new user.
• Command: sudo useradd username

32. How do you delete a user in Linux?


• Answer: The userdel command deletes a user.
• Command: sudo userdel username

33. How do you add a user to a group?


• Answer: The usermod -aG command adds a user to a group.
• Command: sudo usermod -aG groupname username

34. How do you switch users in Linux?


• Answer: Use the su command to switch users.
• Command: su - username
35. What is a shell in Linux?
• Answer: A shell is a command-line interpreter that provides a user interface for the
Linux operating system. Examples include bash, sh, zsh, and csh.
• Command: echo $SHELL

36. How do you check the Linux version?


• Answer: The uname -a command displays system information, including the kernel
version. For distribution-specific information, use lsb_release -a.
• Command: uname -a, `lsb_release -a

37. What is the /etc/passwd file?


• Answer: The /etc/passwd file contains user account information, including
usernames, encrypted passwords, user IDs (UIDs), group IDs (GIDs), user info, home
directories, and default shells.
• Command: cat /etc/passwd

38. What is the /etc/shadow file?


• Answer: The /etc/shadow file stores encrypted user password information and
other password-related settings.
• Command: cat /etc/shadow

39. How do you change your password in Linux?


• Answer: Use the passwd command to change your password.
• Command: passwd

40. What is the purpose of the /etc/fstab file?


• Answer: The /etc/fstab file contains information about disk drives and partitions
that need to be mounted at boot time.
• Command: cat /etc/fstab

41. How do you mount a filesystem?


• Answer: Use the mount command to mount a filesystem.
• Command: mount /dev/device /mnt
42. How do you unmount a filesystem?
• Answer: Use the umount command to unmount a filesystem.
• Command: umount /mnt

43. What is the fstab file used for?


• Answer: The fstab file is used to define how disk partitions, various other block
devices, and remote filesystems should be mounted and integrated into the
filesystem.
• Command: cat /etc/fstab

44. What is swap space?


• Answer: Swap space is a portion of a hard disk used as virtual memory to
supplement physical RAM. It helps in managing memory when the system runs out of
RAM.
• Command: swapon -s

45. How do you create a swap file?


• Answer: You can create a swap file using the following commands:
o Command:
o dd if=/dev/zero of=/swapfile bs=1M count=1024
o mkswap /swapfile
swapon /swapfile

46. How do you make a swap file permanent?


• Answer: Add an entry to the /etc/fstab file.
• Command: echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

47. How do you check disk space usage?


• Answer: The df command displays disk space usage.
• Command: df -h

48. How do you check disk usage of a directory?


• Answer: The du command shows disk usage of files and directories.
• Command: du -sh directory

49. What is the tar command used for?


• Answer: The tar command is used to archive files. It can create, extract, and list the
contents of archives.
• Command: tar -cvf archive.tar directory, tar -xvf archive.tar

50. How do you search for a pattern in a file?


• Answer: The grep command searches for patterns within files.
• Command: grep pattern filename

51. How do you copy files and directories?


• Answer: Use the cp command to copy files and directories.
• Command: cp source destination, cp -r source_directory
destination_directory

52. How do you move or rename files and directories?


• Answer: Use the mv command to move or rename files and directories.
• Command: mv source destination

53. How do you delete files and directories?


• Answer: Use the rm command to delete files and directories.
• Command: rm filename, rm -r directory

54. What is the echo command used for?


• Answer: The echo command outputs the given text or variables to the terminal.
• Command: echo "Hello, World!"

55. How do you display a file's content in reverse order?


• Answer: The tac command displays a file's content in reverse order.
• Command: tac filename

56. How do you display a file's content in hexadecimal?


• Answer: Use the xxd command to display a file's content in hexadecimal.
• Command: xxd filename
57. What is the awk command used for?
• Answer: The awk command is a powerful text processing utility used for pattern
scanning and processing.
• Command: awk '{print $1}' filename

58. What is the sed command used for?


• Answer: The sed command is a stream editor used to perform basic text
transformations on an input stream.
• Command: sed 's/old/new/' filename

59. How do you create an alias in Linux?


• Answer: Use the alias command to create a shortcut for a command.
• Command: alias ll='ls -la'

60. How do you remove an alias in Linux?


• Answer: Use the unalias command to remove an alias.
• Command: unalias alias_name

61. How do you create a symbolic link?


• Answer: Use the ln -s command to create a symbolic link.
• Command: ln -s target linkname

62. How do you create a hard link?


• Answer: Use the ln command to create a hard link.
• Command: ln target linkname

63. What is the nohup command used for?


• Answer: The nohup command allows a process to continue running in the
background after the user has logged out.
• Command: nohup command &

64. How do you display the manual of a command?


• Answer: Use the man command to display the manual of a command.
• Command: man command
65. How do you display the help information of a command?
• Answer: Use the --help option with the command to display its help information.
• Command: command --help

66. What is a package manager?


• Answer: A package manager is a tool that automates the process of installing,
upgrading, configuring, and removing software packages. Examples include apt, yum,
and dnf.
• Command: apt-get install package, yum install package

67. How do you update a package list in Debian-based systems?


• Answer: Use the apt-get update command to update the package list.
• Command: sudo apt-get update

68. How do you upgrade all packages in Debian-based systems?


• Answer: Use the apt-get upgrade command to upgrade all packages.
• Command: sudo apt-get upgrade

69. How do you install a package in Debian-based systems?


• Answer: Use the apt-get install command to install a package.
• Command: sudo apt-get install package_name

70. How do you remove a package in Debian-based systems?


• Answer: Use the apt-get remove command to remove a package.
• Command: sudo apt-get remove package_name

71. How do you install a package in Red Hat-based systems?


• Answer: Use the yum install or dnf install command to install a package.
• Command: sudo yum install package_name, sudo dnf install package_name

72. How do you remove a package in Red Hat-based systems?


• Answer: Use the yum remove or dnf remove command to remove a package.
• Command: sudo yum remove package_name, sudo dnf remove package_name
73. How do you list installed packages?
• Answer: Use the dpkg -l command in Debian-based systems and rpm -qa in Red
Hat-based systems.
• Command: dpkg -l, rpm -qa

74. How do you check the dependencies of a package?


• Answer: Use the apt-cache depends command in Debian-based systems and yum
deplist in Red Hat-based systems.
• Command: apt-cache depends package_name, yum deplist package_name

75. How do you clean up unused packages?


• Answer: Use the apt-get autoremove command in Debian-based systems and yum
autoremove in Red Hat-based systems to remove unused packages and
dependencies.
• Command: sudo apt-get autoremove, sudo yum autoremove

76. What is the purpose of the /etc/hosts file?


• Answer: The /etc/hosts file maps hostnames to IP addresses locally, allowing for
hostname resolution without querying DNS servers.
• Command: cat /etc/hosts

77. How do you configure a network interface?


• Answer: Use commands like ifconfig (older systems) or ip (newer systems) to
configure network interfaces.
• Command: ifconfig eth0 192.168.1.100 netmask 255.255.255.0, ip addr
add 192.168.1.100/24 dev eth0

78. How do you check network configuration?


• Answer: Use the ifconfig or ip addr command to check network configurations.
• Command: ifconfig, ip addr

79. How do you check active network connections?


• Answer: Use the netstat or ss command to check active network connections.
• Command: netstat -tuln, ss -tuln
80. How do you restart a network service?
• Answer: Use service management commands like systemctl or service to restart
network services.
• Command: sudo systemctl restart network.service, sudo service network
restart

81. What is the iptables command used for?


• Answer: The iptables command is used to set up, maintain, and inspect the tables
of IP packet filter rules in the Linux kernel.
• Command: sudo iptables -L

82. How do you enable packet forwarding?


• Answer: Modify the /proc/sys/net/ipv4/ip_forward file to enable packet
forwarding.
• Command: echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

83. What is a firewall in Linux?


• Answer: A firewall in Linux is a system that controls incoming and outgoing network
traffic based on predetermined security rules. iptables and firewalld are common
firewall tools.
• Command: sudo iptables -L, sudo firewall-cmd --state

84. How do you set up a simple firewall rule to block an IP


address?
• Answer: Use iptables to add a rule that blocks an IP address.
• Command: sudo iptables -A INPUT -s 192.168.1.100 -j DROP

85. What is SELinux?


• Answer: SELinux (Security-Enhanced Linux) is a Linux kernel security module that
provides a mechanism for supporting access control security policies.
• Command: getenforce (to check the status), setenforce (to change the mode)

86. How do you disable SELinux temporarily?


• Answer: Use the setenforce command to change SELinux to permissive mode.
• Command: sudo setenforce 0
87. What is the purpose of the /etc/resolv.conf file?
• Answer: The /etc/resolv.conf file specifies the DNS servers that the system
should use for hostname resolution.
• Command: cat /etc/resolv.conf

88. How do you configure DNS settings?


• Answer: Edit the /etc/resolv.conf file to configure DNS settings.
• Command: sudo nano /etc/resolv.conf and add nameserver entries.

89. What is the hostname command used for?


• Answer: The hostname command is used to display or set the system's hostname.
• Command: hostname, sudo hostname newhostname

90. How do you find your system's IP address?


• Answer: Use the ifconfig or ip addr command to find the system's IP address.
• Command: ifconfig, ip addr

91. What is the scp command used for?


• Answer: The scp (secure copy) command is used to securely copy files between
hosts over a network.
• Command: scp file user@remote_host:/path/to/destination

92. How do you create an SSH key pair?


• Answer: Use the ssh-keygen command to create an SSH key pair.
• Command: ssh-keygen -t rsa -b 2048

93. How do you add your SSH key to the SSH agent?
• Answer: Use the ssh-add command to add your SSH key to the SSH agent.
• Command: ssh-add ~/.ssh/id_rsa

94. What is the rsync command used for?


• Answer: The rsync command is used for fast, flexible, remote (and local) file copying
and synchronization.
• Command: rsync -avz source destination
95. How do you check the status of a service?
• Answer: Use the systemctl or service command to check the status of a service.
• Command: sudo systemctl status servicename, sudo service servicename
status

96. How do you start and stop services?


• Answer: Use the systemctl or service command to start and stop services.
• Command: sudo systemctl start servicename, sudo systemctl stop
servicename

97. What is a runlevel in Linux?


• Answer: A runlevel is a mode of operation in Unix and Unix-like operating systems
that defines what system services are operating.
• Command: runlevel

98. How do you change the runlevel?


• Answer: Use the init or telinit command to change the runlevel.
• Command: sudo init 3

99. What is the journalctl command used for?


• Answer: The journalctl command is used to query and display messages from the
journal, which is the systemd logging service.
• Command: journalctl

100. How do you enable and disable services at boot?


• Answer: Use the systemctl command to enable or disable services at boot.
• Command: sudo systemctl enable servicename, sudo systemctl disable
servicename

You might also like