100 interview questions related to Linux administration

397
100 interview questions related to Linux administration

1. What is the difference between UNIX and Linux?

  • Answer: UNIX is a proprietary operating system originally developed by AT&T Bell Labs, while Linux is an open-source operating system inspired by UNIX. Linux distributions are freely available, but UNIX often requires licensing.

2. What is the Linux kernel?

  • Answer: The Linux kernel is the core component of the Linux operating system. It manages system resources, hardware, memory, and provides essential services for all other parts of the system.

3. What is a shell in Linux?

  • Answer: A shell is a user interface for accessing the operating system’s services. It can be command-line based (like Bash) or graphical (like GNOME).

4. How do you check the kernel version?

  • Answer: By using the command uname -r.

5. What is the difference between sudo and su?

  • Answer: sudo allows a permitted user to execute a command as the superuser or another user, while su switches the current user to another user account.

6. How do you check the disk usage of a directory?

  • Answer: By using the du command.

7. How do you search for a specific string inside a file?

  • Answer: By using the grep command.

8. What is the purpose of the etc directory?

  • Answer: The /etc directory contains all the system-wide configuration files and shell scripts used to initialize system settings for the operating system and applications.

9. What is a swap space?

  • Answer: Swap space is a portion of the hard drive that is used as virtual memory when the physical RAM is full.

10. How do you create a new user?

  • Answer: By using the useradd command.

11. How do you terminate a process?

  • Answer: By using the kill command followed by the process ID.

12. What is the difference between soft link and hard link?

  • Answer: A soft link (or symbolic link) is a reference to another file or directory, while a hard link is a direct reference to the data on the disk without referring to the original file.

13. How do you list all installed packages?

  • Answer: For Debian/Ubuntu: dpkg -l, for RedHat/CentOS: rpm -qa.

14. What is the crontab?

  • Answer: Crontab is a tool that allows users to schedule tasks to run automatically at specified intervals.

15. How do you check system logs?

  • Answer: By using the dmesg command or checking files in /var/log/.

16. How do you redirect output to a file?

  • Answer: By using the > or >> operators. For example, echo "Hello" > file.txt.

17. What is the difference between > and >>?

  • Answer: > overwrites the file if it exists, while >> appends to the file.

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

  • Answer: By using commands like cat, less, or more.

19. What is the purpose of the find command?

  • Answer: It’s used to search for files and directories based on different criteria.

20. How do you check the current system’s run level?

  • Answer: By using the runlevel command.

21. What is the difference between a process and a thread?

  • Answer: A process is an independent program in execution, while a thread is the smallest executable unit of a process. Multiple threads can exist within one process.

22. How do you check the available memory in the system?

  • Answer: By using the free command.

23. What is SSH?

  • Answer: SSH (Secure Shell) is a protocol used to securely log onto remote systems.

24. How do you restart a service?

  • Answer: By using the systemctl restart [service-name] command.

25. What is the purpose of the df command?

  • Answer: It’s used to display disk space usage of all mounted filesystems.

26. How do you set environment variables?

  • Answer: By using the export command, e.g., export VAR_NAME=value.

27. What is a package manager?

  • Answer: A tool that automates the process of installing, updating, and removing software packages.

28. How do you check the history of commands executed?

  • Answer: By using the history command.

29. What is the purpose of the pwd command?

  • Answer: It displays the current working directory.

30. How do you change file permissions using numeric mode?

  • Answer: By using the chmod command, e.g., chmod 755 filename.

31. What is the purpose of the ls command?

  • Answer: It’s used to list the contents of a directory.

32. How do you view the start-up messages after boot?

  • Answer: By checking the dmesg output or viewing the /var/log/boot.log file.

33. What is a TTY in Linux?

  • Answer: TTY stands for Teletypewriter. It represents a terminal or console session.

34. How do you check the status of a service?

  • Answer: By using the systemctl status [service-name] command.

35. What is the purpose of the lsof command?

  • Answer: It’s used to list open files and the processes that opened them.

36. How do you check the default gateway in Linux?

  • Answer: By using the route -n or ip route command.

37. What is the purpose of the ifconfig command?

  • Answer: It’s used to configure and display network interfaces.

38. How do you compress files using Linux?

  • Answer: By using commands like tar, gzip, or bzip2.

39. What is the purpose of the mount command?

  • Answer: It’s used to mount filesystems.

40. How do you schedule a task to run at a specific time?

  • Answer: By using the at command.

41. What is the difference between fg and bg in job control?

  • Answer: fg brings a job to the foreground, while bg sends a job to the background.

42. How do you view the partitions on a system?

  • Answer: By using the fdisk -l or lsblk command.

43. What is the purpose of the head and tail commands?

  • Answer: head displays the beginning of a file, while tail displays the end, often used to view real-time logs.

44. How do you send an email from the command line?

  • Answer: By using the mail or sendmail command.

45. What is the purpose of the cut command?

  • Answer: It’s used to remove or “cut out” sections of each line from a file or input.

46. How do you check CPU usage?

  • Answer: By using the top or htop command.

47. What is the purpose of the sort command?

  • Answer: It’s used to sort lines in text files.

48. How do you search for a package in a repository?

  • Answer: For Debian/Ubuntu: apt-cache search [package-name], for RedHat/CentOS: yum search [package-name].

49. What is the purpose of the awk command?

  • Answer: awk is a text processing tool that can perform pattern scanning and text/data extraction.

50. How do you check disk I/O usage?

  • Answer: By using the iostat command.

51. How do you change the hostname of a Linux machine?

  • Answer: By using the hostnamectl set-hostname [new-hostname] command or editing the /etc/hostname file.

52. What is the purpose of the netstat command?

  • Answer: It’s used to display network connections, routing tables, interface statistics, and more.

53. How do you list all running processes?

  • Answer: By using the ps aux or top command.

54. What is the difference between reboot and shutdown -r now commands?

  • Answer: Both commands restart the system, but shutdown -r now provides a warning to all logged-in users.

55. How do you set the system’s timezone?

  • Answer: By using the timedatectl set-timezone [timezone] command.

56. What is the purpose of the touch command?

  • Answer: It’s used to create empty files or update the access and modification times of existing files.

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

  • Answer: By using the usermod -aG [group-name] [username] command.

58. What is the purpose of the which command?

  • Answer: It’s used to locate the executable of a given command.

59. How do you view the manual page for a command?

  • Answer: By using the man [command-name] command.

60. What is the purpose of the passwd command?

  • Answer: It’s used to change the password of a user.

61. How do you display disk usage in a human-readable format?

  • Answer: By using the df -h command.

62. What is the purpose of the ln command?

  • Answer: It’s used to create links between files.

63. How do you check the version of the Linux distribution?

  • Answer: By checking the contents of /etc/os-release or using the lsb_release -a command.

64. What is the purpose of the ping command?

  • Answer: It’s used to test the connectivity between two network hosts.

65. How do you display the first 10 lines of a file?

  • Answer: By using the head -n 10 [filename] command.

66. What is the purpose of the wc command?

  • Answer: It’s used to count lines, words, and bytes in files.

67. How do you change the priority of a running process?

  • Answer: By using the renice command.

68. What is the purpose of the dd command?

  • Answer: It’s used for low-level copying and conversion of raw data.

69. How do you display the last 10 lines of a file?

  • Answer: By using the tail -n 10 [filename] command.

70. What is the purpose of the nohup command?

  • Answer: It’s used to run a command in the background and it will keep running even after you’ve logged out.

71. How do you change the owner and group of a file simultaneously?

  • Answer: By using the chown [user]:[group] [filename] command.

72. What is the purpose of the groups command?

  • Answer: It’s used to display the groups a user is a member of.

73. How do you display the current path?

  • Answer: By using the echo $PATH command.

74. What is the difference between absolute and relative paths?

  • Answer: An absolute path starts from the root directory and specifies the complete directory list to locate a file or folder. A relative path is defined from the current directory.

75. How do you run a command at a specific time every day?

  • Answer: By adding an entry to the crontab using the crontab -e command.

76. What is the purpose of the file command?

  • Answer: It’s used to determine the type of a file.

77. How do you display the number of processors in the system?

  • Answer: By using the nproc command or checking the contents of /proc/cpuinfo.

78. What is the purpose of the watch command?

  • Answer: It’s used to repeatedly run a command at regular intervals and display the output.

79. How do you display the size of a directory including its subdirectories?

  • Answer: By using the du -sh [directory-name] command.

80. What is the purpose of the alias command?

Answer: It’s used to create shortcuts or abbreviations for commands or command sequences.

81. How do you check the available disk space?

  • Answer: By using the df command.

82. What is the purpose of the rmdir command?

  • Answer: It’s used to remove empty directories.

83. How do you find the process ID of a running process?

  • Answer: By using the pgrep [process-name] command.

84. What is the purpose of the date command?

  • Answer: It’s used to display or set the system date and time.

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

  • Answer: By using the find command.

86. How do you list all environment variables?

  • Answer: By using the env or printenv command.

87. What is the purpose of the sed command?

  • Answer: sed (stream editor) is a tool used to perform basic text transformations on an input stream or file.

88. How do you check the last reboot time?

  • Answer: By using the who -b command.

89. What is the purpose of the alias command?

  • Answer: It’s used to create shortcuts for commands or command sequences.

90. How do you check the version of a specific package?

  • Answer: For Debian/Ubuntu: dpkg -l [package-name], for RedHat/CentOS: rpm -q [package-name].

91. What is a zombie process?

  • Answer: A process that has completed execution but still has an entry in the process table.

92. How do you set a static IP address?

  • Answer: By editing the network configuration file, typically located in /etc/network/interfaces or /etc/sysconfig/network-scripts/.

93. What is the purpose of the route command?

  • Answer: It’s used to show/manipulate the IP routing table.

94. How do you view the list of users currently logged in?

  • Answer: By using the who or w command.

95. What is a inode?

  • Answer: An inode is a data structure that stores information about a file or directory, such as its owner, permissions, timestamps, etc.

96. What is the purpose of the chmod command?

  • Answer: chmod is used to change the permissions of a file or directory.

97. How do you check the IP address of a Linux machine?

  • Answer: By using the ifconfig or ip a command.

98. What is a daemon?

  • Answer: A daemon is a background process that runs independently of interactive user sessions.

99. How do you list all open ports?

  • Answer: By using the netstat -tuln or ss -tuln command.

100. What is the purpose of the chown command?

  • Answer: chown is used to change the owner and group of a file or directory.