You are on page 1of 9

50 Advanced Linux Interview

. Questions along with detailed


. Answers:

1. What is the difference between hard links and soft links?

o Answer: Hard links point directly to the inode of a file, while soft links
(or symbolic links) are separate files that contain the path to the target
file.

2. Explain the significance of the 'root' user in Linux.

o Answer: The 'root' user is the superuser with administrative privileges.


It has the highest level of access and can perform any operation on the
system.

3. How do you find all files modified in the last 10 minutes in a directory
and its subdirectories?

o Answer: Use the find command: find /path/to/directory -mmin -10.

4. What is a kernel in Linux?

o Answer: The kernel is the core of the operating system that manages
hardware resources and provides essential services for other parts of
the system.
5. Explain the purpose of the 'chmod' command.

o Answer: 'chmod' changes the permissions of a file or directory. It can


add or remove read, write, and execute permissions for the owner,
group, and others.

6. How can you find out the current runlevel of a Linux system?

o Answer: Use the runlevel command: runlevel.

7. Explain the role of the 'grep' command in Linux.

o Answer: 'grep' is used for searching text patterns in files. It can search
for patterns using regular expressions and display matching lines.

8. What is the purpose of the 'df' command?

o Answer: 'df' displays information about disk space usage on the


filesystem.

9. Explain the 'ps' command and how it is used to view processes.

o Answer: 'ps' shows information about currently running processes.


Common options include ps aux to display detailed information about
all processes.

10. How do you change the priority of a process in Linux?

o Answer: Use the nice command to run a process with a specified


priority. For example, nice -n 10 command sets a lower priority.
11. What is the purpose of the 'awk' command?

o Answer: 'awk' is a versatile text processing tool that performs pattern


scanning and text extraction. It is often used for data manipulation and
reporting.

12. Explain the role of the 'tar' command in Linux.

o Answer: 'tar' is used for creating and extracting archive files. It bundles
multiple files into a single archive file and can compress the archive
using various algorithms.

13. How can you check the connectivity between two hosts using the 'ping'
command?

o Answer: Use the ping command followed by the target IP or


hostname: ping <target>.

14. What is a cron job, and how do you create one?

o Answer: A cron job is a scheduled task in Linux. To create one, use


the crontab -e command and add an entry specifying the schedule and
the command to be executed.

15. Explain the purpose of the 'iptables' command.

o Answer: 'iptables' is used for configuring the Linux kernel's netfilter


firewall. It can filter, modify, or redirect network packets.

16. How do you list all open ports on a Linux system?

o Answer: Use the netstat or ss command. For example, netstat -


tuln or ss -tuln.
17. What is the purpose of the 'find' command in Linux?

o Answer: 'find' is used to search for files and directories in a directory


hierarchy based on various criteria.

18. Explain the significance of the 'passwd' file in Linux.

o Answer: The 'passwd' file stores user account information, including


usernames and encrypted passwords.

19. How can you check the available disk space on a specific filesystem using
the 'du' command?

o Answer: Use du -h /path/to/filesystem to display disk usage in a


human-readable format.

20. Explain the purpose of the 'curl' command.

o Answer: 'curl' is a command-line tool for making HTTP requests. It is


often used to download or upload data to/from web servers.

21. What is the purpose of the 'dd' command in Linux?

o Answer: 'dd' is used for copying and converting files and can be used
for tasks like creating disk images or cloning drives.

22. How can you set environment variables in Linux?

o Answer: Use the export command. For example, export


MY_VARIABLE="value".
23. What is the difference between a process and a thread?

o Answer: A process is an independent program with its memory space,


while a thread is a lightweight process that shares the same memory
space as other threads in the same process.

24. Explain the purpose of the 'mount' command in Linux.

o Answer: 'mount' is used to attach a filesystem to the directory tree. It


allows the operating system to access the files on the filesystem.

25. How do you find the top 5 memory-consuming processes on a Linux


system?

o Answer: Use the ps command with the --sort option: ps aux --sort=-
%mem | head -n 6.

26. What is a symbolic link, and how do you create one using the 'ln'
command?

o Answer: A symbolic link is a pointer to another file. To create one, use


the ln -s command: ln -s target_file link_name.

27. Explain the purpose of the 'sed' command in Linux.

o Answer: 'sed' is a stream editor used for text manipulation, such as


search and replace, text insertion, and deletion.

28. How can you run a Linux command in the background?

o Answer: Append & to the command, e.g., command &. Alternatively, use
the nohup command to keep a command running after logging out.
29. What is the 'sudo' command, and how is it used in Linux?

o Answer: 'sudo' allows a permitted user to execute a command as the


superuser or another user. Users must be listed in the sudoers file.

30. Explain the purpose of the 'journalctl' command.

o Answer: 'journalctl' is used to query and display messages from the


journal, a centralized logging system on modern Linux systems using
systemd.

31. How do you find the IP address of a Linux system?

o Answer: Use the ip addr show or ifconfig command to display network


interface information.

32. What is the purpose of the 'kill' command in Linux?

o Answer: 'kill' is used to send signals to processes. The default signal is


SIGTERM, which requests the process to terminate.

33. How can you compress and decompress files using the 'gzip' command?

o Answer: To compress: gzip file.txt. To decompress: gunzip


file.txt.gz.

34. Explain the purpose of the 'useradd' command in Linux.

o Answer: 'useradd' is used to add new user accounts to the system.


35. How can you create a shell script in Linux?

o Answer: Use a text editor to create a script with a shebang


(#!/bin/bash) at the top, make it executable with chmod +x script.sh,
and then run it with ./script.sh.

36. What is a 'daemon' in Linux?

o Answer: A daemon is a background process that runs without direct


user interaction. It typically performs system tasks or provides services.

37. How do you check the version of the Linux kernel?

o Answer: Use the uname -r command.

38. Explain the purpose of the 'chown' command in Linux.

o Answer: 'chown' changes the owner of a file or directory. For


example, chown user:group file.txt.

39. What is the purpose of the 'uptime' command in Linux?

o Answer: 'uptime' displays how long the system has been running, the
number of users, and the system load averages.

40. How do you monitor system resource usage using the 'top' command?

o Answer: Run the top command. Press 'q' to exit. 'top' shows real-time
information about processes and resource usage.

41. What is the purpose of the 'echo' command in Linux?

o Answer: 'echo' is used to print text to the terminal or redirect it to a


file. For example, echo "Hello, World!".
42. Explain the significance of the '/etc/passwd' file.

o Answer: '/etc/passwd' contains information about user accounts,


including usernames, user IDs, group IDs, home directories, and login
shells.
43.

44. How do you check the status of a service using the 'systemctl' command?

o Answer: Use systemctl status service_name. For example, systemctl


status sshd.

45. What is the purpose of the 'route' command in Linux?

o Answer: 'route' displays or modifies the IP routing table.

46. How can you monitor disk I/O in real-time using the 'iotop' command?

o Answer: Install 'iotop' if not installed (sudo apt-get install iotop) and
then run sudo iotop.

47. Explain the purpose of the 'nmcli' command.

o Answer: 'nmcli' is a command-line client for NetworkManager. It allows


users to control and monitor network connections.

48. How do you find and kill a process using its process ID (PID)?

o Answer: Use the ps command to find the PID and then kill PID to
terminate the process.

49. What is the purpose of the 'ldd' command?

o Answer: 'ldd' is used to print shared library dependencies of an


executable or a shared library file.
50. Explain the purpose of the 'scp' command in Linux.

o Answer: 'scp' is used to securely copy files between hosts over a


network.

51. How do you create a RAM disk in Linux?

o Answer: Use the 'mount' command with the '-t tmpfs' option: sudo
mount -t tmpfs -o size=512M tmpfs /mnt/ramdisk . Adjust size and mount
point as needed.

You might also like