Saturday, May 6, 2023

Top 50 Linux Interview Questions Answers for 3 to 5 Years Experienced

Linux is the #1 operating system for hosting real world production application. Most of the real world Java application in big IBs are hosted on RedHat Linux. This makes Linux an extremely important skill for getting a Job. Along with any programming language e.g. Java or C++, you must have good command on Linux and SQL to get a programming job. Btw, Linux is not just limited for development job but it is even more important for support roles and system admin jobs. If you are working in production support then an excellent knowledge of Linux is expected from you, which includes knowing fundamental of Linux e.g. how Linux OS works?, what is kernel or shell?, or what is init process?, as well as good knowledge of various Linux commands to perform day-to-day job, and troubleshoot any production issues. 

In this article, we'll focus on Linux Interview questions mainly for developer and IT support professionals and not so much for system admins which require even deeper level of knowledge. They are suppose to know a lot more than programmers and support guys. 

In this list you will find questions which is mainly task based e.g. how will you check if a process is running or not? In order to answer this kind of question, you must have sound knowledge of various Linux commands and their usage. 

You can divide Linux commands on a couple of categories e.g. networking commands like telnet, nslookup, netstat, file system commands like ls, du, mkdir, file permissions e.g. chmod, chown etc, process related commands e.g. ps and top and debugging tools e.g. lsof

Once you gone through these list of questions you are good for any Linux technical interview at least for phone round. The list also includes scenario based Linux interview questions and answers e.g. how do you find the top 5 large files if your file system is about to fill? or what do you do if your Linux machine suddenly become very slow?

I have also tried to include a lot of Linux networking interview questions and answers because they are extremely important from troubleshooting perspective.Since almost all Linux system is connected to each other and you often work on a client server application where one application connects to many hosts and problem on one affects other, it is extremely important you know about basic Linux networking commands to quickly troubleshoot the root cause.Some of the Linux questions are advanced keeping experienced programmer in mind, so if you don't know their answer then its ok. 



30 Linux Command Interview Questions and Answers for Programmers and Developers

So, what we are waiting for let's start with practice Linux questions for technical interviews:

1. How do you call a web service from Linux command line?
Well, a web service call is nothing but an HTTP request and there are a couple of Linux commands you can use to send HTTP request from command line e.g. cURL and wget. In order to test RESTful Web Services from Linux, I often use cURL command as shown below:

$ curl https://api.stripe.com/v1/charges \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2:

curl uses the -u flag to pass basic auth credentials (adding a colon after your API key prevents cURL from asking for a password).

2. What is the Linux command to check how much space is filled/remaining in a filesystem?
You can use the df command in Linux to check the how much left in a particular filesystem. Best way to check is go to the directory and issue the df -h . command which will display the space stats for current file system. The option h is for human readable e.g. size will be printed in GB or MB instead of bytes.

$ df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/docker-202:1-787972-259ae8d29832 10G 1.4G 8.7G 14% /


3. How do you find top 5 large files when your file system is full?
You can use the disk usage (du) command as shown below:

$ du -s * | sort -nr

don't use usual du -sh * where h stands for human readable and print size in kilo byte (k), mega byte (m) or Giga byte (G) because then sort command will not work as expected. By just printing their size in bytes you can sort them using sort -nr option. 

4. How would you create a file named abc.txt in your current directory?
You can use the touch command to create a file in any directory including current directory, for which you just need to pass dot (.) as shown below
$ touch abc.txt
$ touch ./abc.txt

both will create abc.txt in current directory. 

5. How would you change to one directory above the current working directory?
You can use cd command to change directory and to go to one level up you can use the shortcut for parent directory which is double dot (..) as shown below

$ cd ..

6. How do you go to home directory in Linux?
This is the follow-up question of previous Linux interview question. you can use the same cd command to go to home directory but instead of using .. you can use ~ or just give nothing as shown below

$ cd
or 
$ cd ~ 

both will take you to home directory. It's also one my favorite Linux tip to work fast in command line. 

7. how do you go to previous directory in Linux?
This is the third question on the same cd command, this time you need to use cd - to go to previous directory. These are quite useful tips to navigate from one directory to another in Linux. You can find more such tips on how to work fast in Linux. 
$ cd - 

8. How to check if a remote host is up and running?
You can use ping command to ping the server, if server responds means it is up. 

9. How to check if an application listening on port 8080 is up?
You can use telnet command to check if a process is up and listening on port 8080

10. How to find all TCP connection made by your application?
You can use netstat command in Linux to find all the TPC connections made by your application, but you need to first find the PID of a process

11. How do you go from one host to another in Linux network?

12. How do you make a file read only in Linux?
You can make a file read only in Linux by using chmod command and giving it only read permission as shown in following example:

$ chmod 400 MyApp.java
400 means 100 000 000 means r-- --- --- i.e. read only for owner. Now file is read only and only owner can read it “-r--------"

13. How do you change permission of file or directory in Linux?
You can change permission using chmod command as shown in following example:

14. How do you sort results of a command in Linux?
You can use the sort command to sort the result of any command in Linux as shown in following exmaple:
$ ~/test cat names | sort
electronic trading
forex trading
stocks trading
stocks trading

You can also use the option sort - u to remove duplicate entries as shown below:
$ ~/test cat names | sort -u
electronic trading
forex trading
stocks trading

15. How do you kill a process in Linux?
You can use the kill command in Linux to kill a process as shown in following example:
$ ps -ef| grep process_identifier // will give you PID
kill -9 PID

15. What is difference between kill -9 and kill -3 in Linux?
There is a subtle difference between them, kill -9 is force kill but kill -3 is used to take thread dump of the process. 

17. How do you redirect output of a command to a file?

$ cat abc.txt > copy.txt

will copy content from abc.txt to copy.txt in Linux

18. What is difference between < and << in Linux?
The first one redirect output to a file and overwrite the file if it exists while << append the output into existing file. The first option is used to create a new file with the result of any command while second option is used to append data into an existing command. 

19, What happens when you do nslookup to amazon.com?
It ask for IP address of amazon.com from the default name server. If you want to use a specific name server you can do by providing hostname or IP address e.g. nslookup - nameserver1

20. Where does it pick the IP address? 
(from the name server)

21. What do you do if you can login to a server but its very slow? 
top? what will you look? load factor

22. How you transfer a file from one server to another?
You can use SCP or SFTP to transfer files securely between one server to another in a Linux network. This is a good Linux command interview questions which focuses on day-to-day jobs in a multi-national company. 

23. How do you check the command line of a process? 
(find the PID and then use cat /proc/PID/cmdline)

24. What is full form of nslookup? 
(name server lookup), you can also check this article to learn how nslookup works in Linux

25. What are different places which can be used to convert IP address to hostname or vice versa? 
(hosts file /etc/hosts, name server, NIS (network information services)

26. what is load average on top?

27. How do you update a symbolic link in Linux?

$ ln -sf abc.txt current
$ ln -sf abc.txt previous

28. Can you explain file permissions in Linux, how can you make a file read only in Linux?
You can use chmod command to make a file read only in Linux, just provide 660 permission to blank out write permission. Here is a complete guide of Linux file permissions:

Top 50 Linux Interview Questions and Answers for 3 to 5 Years Experienced IT Professionals



Linux Operating System Interview Questions and Answes

So far we have seen the Linux questions based upon task, scenarios and command based, now let's checkout out interview questions based upon Linux operating system concepts. 

1. What is inode?
A data structure to hold information related to a file.

2. What is a shell?
It's software which takes user input from the command line and executes it e.g. bash shell, C shell, K shell etc

3. What is a mountpoint?
A logical representation of a physical file system

4. What is difference between hard link and soft link?
A hard link cannot point to directories and cannot cross the file system boundaries. It will always point to file even if file is moved or removed.

5. How does inter-process communication happen in Linux?
By using pipe, sockets and shared memory.

6. how do you list all files in a directory including hidden files?
ls - alrt

7. how do you pass a parameter to a shell script?
 (using $)

8. How do you find which sudo command you are allowed to execute?
 (sudo -l)

9. how do you find who else is logged into a server? 
You can use finger command to find out which other users have logged into machine

10. how do you find current active connection open on a Linux server?
 (netstat -na | grep ESTABLISED)

11. How do you start bash shell? 
(/bin/bash)

12. how to set an environment variable in Linux? 
(export PATH=$PATH:.)

13. Can you write down a crontab entry to run from Monday to Friday at 0500, to delete all files from /tmp directory, recursively
00 05 * * 1-5 'rm -rf /tmp/*.*

14. What is backquotes (`) used for in shell scripting? 
 you can use it to execute a command and store its output e.g. now = `date`

15. How do you find top 5 file or directory which is taking most of the space in a file system?
see the questions number 5 in first section for answer

16. how do you list all open files by your process?
using lsof command

17. How do you find how much RAM left in your machine?
using free command you can find status of memory and swap space. you can use -g or -m option to print memory in GB or MB.

18. How do you convert hostname to IP address in Linux?
There are multiple opiton to convert IP address to hostname and vice-versa in Linux  the easiest one is by using nslookup command

19. How do you run a process in background? 
(By using &)

20. What is different using nohup command and running process using &?
nohup means no hang-up means command will not be terminated even if remote session which executed those command has been closed, while background job will terminate as soon as remote session is closed.

21. how do you kill a process in Linux?
kill -9 process id

22. How do you find all process for a particular user?
ps -ef | grep username

23 How do you bring a background process into foreground?
by using fg job_id, you can find the job id by running the jobs command.


That's all about some of the frequently asked Linus Interview Questions from programming job interviews. These questions are great to refresh your knowledge about Linux commands before going for any face-to-face or phone interviews. The standard of question is easy and if you have worked in Linux for a couple of years then you can answer all of them except some of the advanced questions which are target for more experienced. 

Other Technical Interview Questions you may like to explore for practice
  • 15 Data Structure and Algorithm Questions from Java Interviews (read here)
  • Top 10 Spring Framework Interview Questions with Answers (see here)
  • 20 Java Design Pattern Questions asked on Interviews (see here)
  • 15 Java NIO and Networking Interview Questions with Answers (see here)
  • 10 Servlet Interview Questions with Answers (see here)
  • 10 popular Struts Interview Questions for Java developers (list)
  • Top 40 Core Java Phone Interview Questions with Answers (list)
  • Top 10 Trick Java Interview Questions and Answers (see here)
  • 20 Tibco Rendezvous and EMS Interview Questions (read more)
  • 10 Oracle Interview Questions for Java developers (see here)
  • Top 10 XSLT Interview Questions with Answers (read more)
  • Top 10 EJB Interview Questions and Answers (see here)
  • 40 HashMap Interview questions with Answers (hashmap questions)
  • Top 10 JMS and MQ Series Interview Questions and Answers (list)
  • 20 Spring Boot Interview Questions with Answers (spring boot questions)
  • 10 JDBC Interview Questions for Java Programmers (questions)
  • 12 RESTful Web Services Questions from Interviews (read here)
  • 10 XML Interview Questions for Java Programmers (read here)
  • Top 10 JSP Questions  from J2EE Interviews (read here)
  • 10 Hibernate Interview Questions for Java EE developers (see here)
  • 20 jQuery Interview Questions for Java Web Developers (list)
  • 15 Microservice Interview Questions with Answers (Microservice questions)

Thanks for reading this article. If you like these Linux and Operating System interview questions and their answers then please share with your friends and colleagues. If you have any question, feedback or any doubt about these questions/answers, please drop a comment.

P. S. - If you are new to Linux and want to learn Linux in depth, both commands and concepts then I also suggest you to go through these online Linux and Shell Scripting training courses to learn Linux in depth. I have shared best online courses to learn Linux from sites like Udemy, Coursera, and CodeCademy based upon my experience. 

1 comment :

Anonymous said...

Thanks for sharing.. Request to share questions related to DBMS Linux administrator.

Post a Comment