Linux interview questions

LINUX INTERVIEW QUESTIONS & ANSWERS (PART 1)


--- I. LINUX BASICS & NAVIGATION ---


1. What is the use of Echo command?

Answer: It outputs the strings/arguments passed to it onto the terminal.


2. How to check the computer name or host name in the server?

Answer: Use the 'hostname' command.


3. How to check the current user in Linux terminal?

Answer: Use the 'whoami' command.


4. How to check your current path or directory you are working in?

Answer: Use the 'pwd' (Present Working Directory) command.


5. Explain the difference between relative and absolute path.

Answer: Absolute path starts from root (/); Relative path starts from the current directory.


6. Which command to be used to create a file in Linux?

Answer: Use 'touch', 'vi', 'vim', or 'nano'.


7. How will you edit an existing file on the Linux server?

Answer: Use editors like 'vi', 'vim', or 'nano'.


8. How to rename a file in Linux?

Answer: Use the 'mv' (move) command.


9. How to search for a string in a file?

Answer: Use the 'grep' command.


10. Difference between grep and egrep.

Answer: 'egrep' (Extended Grep) allows searching for multiple strings at once using pipe (|) separators.


11. How can you read a file without using the cat command?

Answer: Use 'less', 'more', or 'vi'.


12. What is the advantage of using the less command?

Answer: It handles large files efficiently and allows both forward and backward searching.


13. How to check our files permission?

Answer: Use 'ls -l', 'll', or 'getfacl'.


14. How to check the IP of your Linux server?

Answer: Use 'ifconfig' or 'ip addr'.


15. How to read the top five lines in a file?

Answer: Use 'head -5 [filename]'.


16. How to read the last five lines in a file?

Answer: Use 'tail -5 [filename]'.


17. How to list the hidden files?

Answer: Use 'ls -la'. Hidden files start with a dot (.).


18. How to see all the recently used command?

Answer: Use the 'history' command.


19. What is root (Admin/Home/Root Directory)?

Answer: Root is the superuser, /root is the admin's home, and / is the system's top-level directory.


20. What is the inode and how to find it for a file?

Answer: An inode is a unique metadata identifier; find it using 'ls -li'.


21. Which command can you use for finding the files on a Linux system?

Answer: Use the 'find' or 'locate' command.


22. Command for counting words and lines.

Answer: Use 'wc' (Word Count); 'wc -l' for lines.


23. How can you combine two commands or what is pipe used for?

Answer: Use '|' to redirect the output of one command as input to the next.


24. How to view the difference between two files?

Answer: Use the 'diff' command.


25. What is the use of the shred command?

Answer: To permanently delete a file so it is unrecoverable.


26. How to check system architecture info?

Answer: Use 'lscpu' or 'dmidecode'.


27. How to combine two files?

Answer: Use 'cat file1 file2 > file3'.


28. How can you find the type of file?

Answer: Use the 'file' command.


29. How to sort the content of the file?

Answer: Use the 'sort' command.


30. Different ways to access a Linux server remotely.

Answer: Using 'ssh' via tools like PuTTY, Git Bash, or CMD.


--- II. PERMISSIONS & REDIRECTION ---


31. What are the different types of permission for a file in Linux?

Answer: Read (r), Write (w), and Executable (x).


32. Which permission allow a user to run an executable file or a script?

Answer: The Executable (x) permission.


33. How to write the output of a command into a file?

Answer: Use the '>' redirection sign.


34. How to write something in a file without deleting the existing content?

Answer: Use the '>>' (append) sign.


35. How to redirect an error of a command into a file?

Answer: Use the '2>' operator.


--- III. AUTOMATION & SERVICES ---


36. How to automate any task or a script?

Answer: Use Cron jobs with the 'crontab' command.


37. How to check scheduled jobs?

Answer: Use 'crontab -l'.


38. What is the meaning of * * * * * in the Cron job?

Answer: Minute, Hour, Day of Month, Month, and Day of Week.


39. If your Cron job didn't work, how would you check?

Answer: Check system time, crontab syntax, and system logs.


40. What is demon service?

Answer: A background process that runs continuously (e.g., sshd, httpd).


41. How to check if a service is running or not?

Answer: Use 'systemctl status [service_name]'.


42. How to stop or start any service?

Answer: Use 'systemctl start' or 'systemctl stop'.


--- IV. SYSTEM MONITORING & PROCESSES ---


43. How to check for free disk space?

Answer: Use the 'df -h' command.


44. How to check the size of a directory content?

Answer: Use the 'du -sh' command.


45. How to check the CPU usage for a process?

Answer: Use the 'top' command.


46. What is a process in Linux?

Answer: An instance of a running program with a unique PID.


47. How to check if a process or application is running or not?

Answer: Use 'ps -ef' or 'ps -ef | grep [name]'.


48. How to terminate or stop our running process?

Answer: Use the 'kill' command with the PID.


49. Difference between kill and kill -9.

Answer: 'kill' is a graceful shutdown; 'kill -9' is a forceful termination.


--- V. NETWORKING & SSH ---


50. How to check if a IP server is accessible or not?

Answer: Use 'ping' or 'telnet'.


51. Which command to use to get info about ports?

Answer: Use the 'netstat' command.


52. How to check open port on Linux system?

Answer: Use 'netstat -putan' and grep for the port.


53. How to check the network interfaces in Linux?

Answer: Use 'ifconfig' or 'netstat'.


54. Difference between telnet and SSH?

Answer: SSH is encrypted and secure; Telnet is unencrypted and insecure.


55. Which service should be running on server to allow you to connect remotely?

Answer: The 'sshd' service.


56. What is SSH?

Answer: Secure Shell, a protocol for secure remote data communication.


57. Why it is called as secure shell?

Answer: Because communication is in an encrypted format.


58. What is the default port for SSH?

Answer: Port 22.


59. Which command is used to access our Linux system from our term

inal?

Answer: 'ssh [user]@[IP/Hostname]'.


60. What is the first thing to do to transfer a large file (10GB) remotely?

Answer: Compress the file using 'gzip' or 'tar' to reduce its size.





MOCK INTERVIEW SCRIPT: LINUX FUNDAMENTALS


Interviewer: "How do you check for hidden files in a directory, and what distinguishes them from regular files?"

Candidate: "You can use the 'ls -la' command. Hidden files are distinguished by a dot (.) prefix at the beginning of their filename, like '.bashrc'. The '-a' flag ensures these aren't filtered out of the list."




Interviewer: "If a user needs to run a script but gets a 'Permission Denied' error, what is likely the issue and how do you check it?"

Candidate: "The file likely lacks the 'Execute' permission. I would check the permissions using 'ls -l'. If the 'x' bit isn't set for that user, I'd use 'chmod' to grant the necessary execution rights."




Interviewer: "Explain the difference between 'kill' and 'kill -9' when managing processes."

Candidate: "Standard 'kill' sends a SIGTERM signal, which allows a process to save its state and shut down gracefully. 'kill -9' sends a SIGKILL signal, which forces the process to terminate immediately without any cleanup. We usually try 'kill' first and only use '-9' as a last resort."


Interviewer: "How would you automate a cleanup script to run every Sunday at midnight?"

Candidate: "I would use a Cron job. I'd open the configuration with 'crontab -e' and add an entry using the five-star syntax. For Sunday at midnight, it would look like '0 0 * * 0' followed by the path to my script."


Interviewer: "Why is SSH preferred over Telnet for remote access?"

Candidate: "The primary reason is security. SSH encrypts all data, including login credentials, while Telnet transmits everything in plain text. This makes Telnet vulnerable to packet sniffing, whereas SSH keeps the communicati

on channel secure."




LINUX INTERVIEW QUESTIONS & ANSWERS (PART 2)


--- I. DISTRIBUTIONS & CORE COMPONENTS ---


1. What does RHEL Linux stand for?

Answer: Red Hat Enterprise Linux. It is an enterprise-level OS that includes tech support from the company.


2. Give some examples of Linux distributions present in the market.

Answer: CentOS, Ubuntu (very popular), Fedora, and Debian.


3. What is Kernel in the Linux world?

Answer: It is the core interface between computer hardware and its processes. It manages resources and communicates with the hardware.


4. What is swap space?

Answer: It is used when physical memory (RAM) is full. Inactive pages in memory are moved to swap space to free up RAM.


--- II. COMMANDS & FILE MANIPULATION ---


5. How to search a word in a file and replace it in the entire file?

Answer: Use the 'sed' command: sed 's/old-word/new-word/g' filename.


6. What is the use of SCP command?

Answer: Secure Copy. It copies files or directories between a local and a remote system securely using SSH.


7. What is the use of FTP command?

Answer: File Transfer Protocol. It is used to exchange files to and from a remote server or network.


8. What is an Alias and how to set it up?

Answer: An alias is a shortcut for long commands. Setup: alias [name]='[full_command]'.


9. What is the difference between Upgrade and Update?

Answer: 'Update' gets the latest versions of packages from repositories. 'Upgrade' installs those updates and removes obsolete packages.


10. Name default ports for DNS, SMTP, FTP, SSH, DHCP, and Squid.

Answer: DNS: 53, SMTP: 25, FTP: 21, SSH: 22, DHCP: 67/68, Squid: 3128, HTTP: 80, HTTPS: 443.


11. How to check if a package is installed or not?

Answer: Use 'rpm -qa | grep [package_name]'.


12. Which command sends exactly three ping packets to google.com?

Answer: 'ping -c 3 google.com'.


13. Which file contains a list of group names and group IDs?

Answer: /etc/group.


14. How can you check the exit status of the previously executed command?

Answer: Use 'echo $?'. 0 means success; any other number means failure.


15. Which command displays the number and type of processors?

Answer: 'lscpu' or reading the '/proc/cpuinfo' file.


16. Which command should you use to get a list of connected USB devices?

Answer: 'lsusb'.


17. Which environment variable is the default for 'cd' when no directory is provided?

Answer: The $HOME variable.


18. True or False: A command following a semicolon (;) executes regardless of the previous command's status.

Answer: True.


19. What are the valid values of the exit status?

Answer: Between 0 and 255.


20. According to FHS, what is the correct directory for log files?

Answer: /var/log.


21. What port must be open to Ping a given host?

Answer: Ping doesn't use a port; it uses ICMP (Internet Control Message Protocol).


22. How do you transfer files between Linux and Windows?

Answer: Using tools like WinSCP or FileZilla, or protocols like SFTP/FTP.


23. Can you split a file into two?

Answer: Yes, using the 'split' command.


24. How can you get unique values from a list?

Answer: Sort the file first, then use the 'uniq' command ('sort file | uniq').


25. Using VI editor, how do you edit and save a file?

Answer: Press 'i' to insert, type text, press 'Esc', then type ':wq' to save and exit.


26. What is the difference between find and locate command?

Answer: 'locate' searches its own indexed database (needs updates); 'find' searches the live file system.


27. What is the 'tee' command used for?

Answer: It displays output on the terminal and writes it to a file simultaneously.


28. What is 'xargs' used for?

Answer: It converts standard input into command-line arguments for another command.


29. How can you find the number of files/folders in a directory?

Answer: 'ls -1 | wc -l'.


30. How do you read only lines 20 to 30 of a file?

Answer: Use a combination of head and tail: 'head -30 filename | tail -11'.


31. What is the use of the 'tar' command?

Answer: To compress multiple files or directories into a single archive file.


32. How to redirect both standard output and error to a file?

Answer: '[command] > file 2>&1'.


33. Name some commands for DNS resolution.

Answer: ping, nslookup, dig, and host.


34. What is the use of 'at' command?

Answer: To schedule a task to run automatically only once at a specific time.


35. Which service is used by 'at' command?

Answer: atd (at daemon).


--- III. PERMISSIONS, ACLs & LINKS ---


36. Which command assigns read-only to everyone and write to the owner?

Answer: 'chmod a+r,u+w [filename]'.


37. Which command changes group ownership of a directory?

Answer: 'chgrp'.


38. What does 'chmod 777' do?

Answer: It gives read, write, and execute permissions to everyone (User, Group, Others).


39. What is ACL and its advantage?

Answer: Access Control List. It allows you to provide specific permissions to a specific user.


40. What are links in Linux and their types?

Answer: Connections between a filename and data on disk. Types: Hard links and Soft (symbolic) links.


41. What is the difference between Hard and Soft links?

Answer: Soft links break if the original file is deleted. Hard links remain functional as they are a replica of the data.


--- IV. ENVIRONMENT & PROCESSES ---


42. What command shows all environment variables?

Answer: 'env' or 'printenv'.


43. What are the levels for setting environment variables?

Answer: Temporary (session level), User level, and Global level.


44. How can you set environment variables?

Answer: Use the 'export' command; for permanence, edit '.bashrc' (user) or '/etc/profile' (global).


45. What command displays the PIDs of a running process (e.g., engine)?

Answer: 'pidof [service_name]'.


46. What is the nice value of a process?

Answer: A value that determines the priority of a process during execution.


47. How to check the nice value of a process?

Answer: 'ps -l' or 'ps -el'.


48. How do you make a process complete faster?

Answer: Change its priority using the 'renice' command.


49. What command checks percentage CPU and memory of a process?

Answer: The 'top' command.


50. How to run a script in the background even after closing the terminal?

Answer: Use the 'nohup' command.


51. How to see all active jobs?

Answer: Use the 'jobs' command.


52. How to resume a stopped job?

Answer: Use 'fg' (foreground) or 'bg' (background).


53. Which command displays kernel-related and hardware messages?

Answer: 'dmesg'.


--- V. ADVANCED FILTERING & SYSTEMS ---


54. How will you see only XML files in a directory?

Answer: 'ls -l *.xml'.


55. How to create 100 files (file1 to file100) in one command?

Answer: 'touch file{1..100}'.


56. How to display files starting with either 'C' or 'M'?

Answer: 'ls [CM]*'.


57. How to show all lines except those starting with '#'?

Answer: 'grep -v "^#" filename'.


58. How to list all files except those beginning with 'A'?

Answer: 'ls | grep -v "^A"'.


59. Which command produces output for 'bat, bet, bit, bot'?

Answer: 'echo b{a,e,i,o}t'.


60. What is a VM (Virtual Machine)?

Answer: A virtual environment that functions as a computer with its own CPU, memory, and OS on physical hardware.


61. How to test a Linux app on Windows?

Answer: Use a Virtual Machine (e.g., VirtualBox or VMware).


62. What is a hypervisor?

Answer: Software that creates and runs virtual machines.


63. What are the types of hypervisors?

Answer: Type 1 (Bare Metal - directly on hardware) and Type 2 (Hosted - on an OS).


64. How to display currently configured logical volumes?

Answer: 'lvs'.


65. How to display configured volume groups?

Answer: 'vgs'.


66. How to check memory usage including swap space?

Answer: 'free' or 'free -h'.


67. How to determine which user's home directory is using the most space?

Answer: Use the 'du' command (Disk Usage).


68. (Wait for Question 68 - skip per video flow)


69. What is the Linux file system?

Answer: A structure used to store and manage data on disk, including files, directories, and permissions.


70. How to check your Linux file system type?

Answer: 'lsblk -f'.





Interviewer: "A file has several occurrences of the word 'Server'. How would you change all of them to 'Node' without opening the file manually?"
Candidate: "I would use the 'sed' command with the global flag. The command would be 'sed -i s/Server/Node/g filename'. The '-i' flag applies the changes directly to the file."

Interviewer: "You have a 10GB log file and you only need to see the entries from line 500 to 600. How do you do it?"
Candidate: "I would combine head and tail. I’d use 'head -600 filename | tail -101' to extract that specific range efficiently without loading the whole file."

Interviewer: "What is the difference between a Hard Link and a Soft Link if I delete the source file?"
Candidate: "If you delete the source file, the Soft Link becomes 'broken' or 'dangling' because it only points to the filename. However, a Hard Link will still work because it points to the actual data (inode) on the disk."

Interviewer: "How can you check if the SSH service is currently running on your server?"
Candidate: "I would use 'systemctl status sshd'. This will tell me if the daemon is active, inactive, or if it has encountered any errors during startup."

Next Post Previous Post
No Comment
Add Comment
comment url