Top 15 UNIX and Linux Interview Questions Answers for 1to 3 Years Experienced

UNIX and Linux Interview Questions and Answers
Hello guys, if you are preparing for technical interviews like Software developer or IT support and looking for some frequently asked Linux and UNIX interview questions then you have come to the right place. In the past, I have shared free Linux courses and today, I am going to share popular Linux and UNIX questions from technical interviews. You might already know that questions from various UNIX operating systems like Solaris, Linux, IBM AIX, or any other UNIX operating system are asked on different support and programming interviews and a good knowledge of essential UNIX concepts and commands goes a long way in cracking these interview as well as working efficiently in your day job. 

I have always seen a few interview questions from Linux and UNIX along with SQL in almost every Java programming interview. You just can not afford not to prepare questions from UNIX and Linux until your Job absolutely doesn't require any work in the UNIX operating system.

I have collected many UNIX command interview questions and already shared them but I found that except for system admin jobs, many programming job interviews only focus on general UNIX commands like chmod, find or grep, and fundamentals like finding files and directories, managing file space, networking commands, checking process status and managing file permissions.

In this article, we will see such kinds of frequently asked interview questions and answers from the UNIX and Linux operating systems. Questions are very fundamental in nature and not limited to Linux only and equally applicable to other UNIX operating systems like Solaris, IBM AIX, etc. 

Many of these UNIX questions are asked during various interviews on companies like TCS, Infosys, Citibank, Wipro, Capgemini, and Tech Mahindra. As I said they are very fundamental and can be asked in any company.  If you come across any other frequently asked Linux questions which are not on this list feel free to suggest.

Btw, if you are new to Linux then I also suggest you first go through comprehensive and hands-on Linux courses to learn basics and essential commands. If you need a recommendation, I highly recommend you to check Linux Mastery: Master the Linux commands in 11.5 hours course on Udemy. It's the highest-rated Linux course on Udemy and very useful to learn essential Linux commands. 





15 Frequently asked UNIX and Linux Interview Questions and Answers

Here is my list of frequently asked UNIX and Linux interview questions and answers. All these questions are based upon fundamental commands and concepts which are a must for working on any UNIX operating system e.g. Solaris.

1. How to find all the links in a folder in UNIX or Linux?
This is a tricky UNIX question as there is no specific command to find all symbolic links. Though you have a ln command for creating and updating soft links nothing gives you all the links in a directory. You need to use the ls command which lists everything in the directory and then you need to list all the links, as they start with "l" as the first characters, as shown in the above article.

here is the actual UNIX command to find all links in a directory :

linux@nyj872:~ ls -lrt
total 2.0K
-rw-r--r--  1 Linux Domain Users  0 Dec  6  2011 a
drwxr-xr-x+ 1 Linux Domain Users  0 Sep 19 12:30 java/
lrwxrwxrwx  1 Linux Domain Users  4 Sep 19 12:31 version_1.0 -> java/

linux@nyj872:~ ls -lrt | grep '^l'
lrwxrwxrwx  1 Linux Domain Users  4 Sep 19 12:31 version_1.0 -> java/

2. How to find a process and kill that?
Another classic UNIX interview question. The answer to this question is simple if you are familiar with ps, grep, and kill commands. by using "ps -ef" you can get a list of all processes and then use grep to find your process and get the PID of that process. Once you got PID you can use the kill command to kill that process as shown in this example of kill command in UNIX.

Linux command interview questions and answers for programmers




3. How to run a program in the background in UNIX or Linux?
an easy UNIX or Linux interview question, only when you know. You can use & to run any process in the background and then you can use jobs to find the job id for that process and can use fg and bg command to bring that process into the foreground and background. See how Linux works book to learn more about running a process in the background.


Linux interview questions and answers


4. How to sort the output of a command in reverse order in Linux or UNIX?
One more Linux commands interview question which checks knowledge of frequently used commands. you can use the sort command in UNIX to sort the output of any command by using PIPE. By using -r option with the sort command you can sort the output of any command in reverse order. See these sort command examples for more details.


5. How to create an archive file in UNIX or Linux Operating System?
Another interview question is based on knowledge of UNIX or Linux command. you can use the tar command to great archives in UNIX or Linux. you can even combine tar and gzip to create a compressed archive in UNIX.


6. What is the meaning of a file that has 644 permission?
To answer this UNIX or Linux interview question, you must know the basics of files and directories in UNIX.  The 644 represents permission 110 for the owner, permission 100 for the group, and 100 for others which means read + write for an owner who creates that file, and read-only permission for the group and others. 

You can also see The Linux Command Line Basics course on Udemy to learn more about essential shell commands in Linux.


best course to learn Linux commands for beginners



7. How will you remove empty files or directories from /tmp ?
You can use the find command to find all the empty files and directories and then combine the output with the xargs command to remove all empty files from /tmp or any other directory in UNIX. See how to delete empty directories and files in UNIX  for exact command and to answer this UNIX command interview questions in detail.


8. I have read permission on a directory but I am not able to enter it why?
One more tricky UNIX question. In order to get into a directory, you need to execute permission. if your directory does not have to execute permission then you can not go into that directory by using the cd command. read UNIX files and directory permissions for more information.


9. How do you find all files which are modified 10 minutes before?
This is another Linux interview question from frequently used commands e.g. find and grep. you can use -mtime option of the find command to list all the files which are modified 10 or m minutes before. see these find command examples for more details.


10. How do you find the size of a directory in UNIX or Linux?
This is another tricky and bit tough Linux interview question as the popular ls command doesn't show the complete size of directories in UNIX. you need to use the du command to get a full size of directories including all subdirectories in UNIX. See How to find directory size in UNIX for exact command and detailed explanation.

You can also check out Learn Linux in 5 Days and Level Up Your Career course on Udemy to learn more about essential Linux commands. One of the best online courses to learn Linux in depth. 

best online course to learn Linux for interviews




11. How do you find all the processes listening on a particular port in Linux? 
You can use the netstat command to find all the processes which are listening on a particular port as shown below:

$ netstat -nap | grep 8084
(Not all processes could be identified, non-owned process info will
 not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:8084 0.0.0.0:* LISTEN 25314/java

Here 25314 is the process id of a tomcat server running on Linux. Since Tomcat is a Java web application it started with the java command and that's why you see 25314/java. See here to learn more about the netstat command in UNIX.



12. How do you find all the process which has opened a file in Linux? 
You can use the lsof (list open files) command to find out the process which has a file handle on the particular file. It's a very useful command to check which process is reading a file. You can use the lsof command as shown below to find out all the processes:

$ lsof /home/someuser/somefile

will list all the process which has opened this file. you can see the command, PID, user, and full file path to find out the process. See here to learn more about the lsof command in Linux.


Linux and UNIX Interview Questions with Answers



13. How to send HTTP requests from a Linux server? 
You can use either the wget or curl command to send HTTP requests, both GET and POST from a Linux machine as shown below:

$ curl http://api.openweathermap.org/data/2.5/weather?q=London,uk
                                &appid=bd82977b86bf27fb59a04b61b657fb6f
{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":804,"main":"Clouds",
"description":"overcast clouds","icon":"04n"}],"base":"stations",
"main":{"temp":282,"pressure":1022,"humidity":87,"temp_min":277.15,
"temp_max":285.15},"visibility":10000,"wind":{"speed":1.5},
"clouds":{"all":90},"dt":1445577409,"sys":{"type":1,"id":5093,
"message":0.0201,"country":"GB","sunrise":1445582275,"sunset":1445619056},
"id":2643743,"name":"London","cod":200}

Here we have sent a GET request to http://api.openweathermap.org and received a JSON response. You can also specify timeout using the curl -m option, see here to learn more about the curl command in UNIX.



14. How do you create a full directory structure like /parent/child/grandchild in UNIX? 
Well, you can use the mkdir command with option -p to create all parent directories in one go as shown below:

[# ~]$ mkdir -p software/java/app/config
[# ~]$
[# ~]$ pwd
/home/john
[# ~]$ cd software/java/app/config/
[# ~/software/java/app/config]$

You can see here software/java/app/config directory is created in just one command. See here to learn more about the mkdir command in UNIX



15. How do you edit a large text file in UNIX without opening it? 
You can use the sed command to edit a large file in UNIX without opening it. The sed stands for stream editor and you can do find replace in a file as shown below:


$ sed 's/Apple/Microsoft/' bestphone.txt


This command will find "Apple" in line and replace it with the "Microsoft" string in the file bestphone.txt.


These were some of the frequently asked UNIX and Linux command interview questions and answers which appear in many IT Job interview which requires knowledge of UNIX operating system, Including programming job interviews like core Java and J2EE interviews. Questions from UNIX and Linux are also very popular during C and C++ programming interviews.




Related UNIX Command Tutorials
  • 10 examples of date command in Linux (examples)
  • 7 Best Bash Shell Scripting courses for Beginners (courses)
  • How to get an IP address from the hostname and vice-versa in Linux (command)
  • 10 examples of the xargs command in Linux (examples)
  • 5 Free Courses to learn Linux for Beginners (Free courses)
  • 10 examples of tar command in UNIX (examples)
  • 6 Free Courses to learn Bash Shell Scripting (Free courses)
  • 10 examples of Vim in UNIX (examples)
  • 5 Best Courses to learn VIM Editor in Linux (best courses)
  • How to create, update and delete soft link in UNIX (command)
  • 5 examples of sort command in Linux (examples)
  • 6 Free Courses to learn Bash scripting in-depth (free courses)
  • 5 examples of kill command in Linux (examples)
  • 10 examples of chmod command in UNIX (examples)
  • Top 5 Courses to learn Linux and Shell Scripting (top courses)
  • 10 examples of cut command in Linux (examples)
  • 10 Books every Linux Power user should read (books)
  • 10 Best Linux Courses for Programmers and Developers (Courses)

Thanks for reading this article so far. If you like these Linux Interview Questions for Beginners, then please share them with your friends and colleagues. If you have any questions or feedback, then please drop a note.

P. S. - If you are new to Linux and looking for a free online training course to learn essential commands and concepts in Linux then I also suggest you check out Learn The Linux Command Line: Basic Commands free course on Udemy. It's completely free and more than 50,000 students have enrolled in this course. 

17 comments:

  1. My putty keep disconnecting when working over SSH and travelling, is there a way to solve that ?

    ReplyDelete
    Replies
    1. increase the seconds between keepalive

      Delete
    2. Enter the command below, it will not disconnecting:

      export TMOUT=3600000000

      Delete
  2. 1) How to find all the links in a folder in UNIX or Linux ?

    Why can't we use find instead of ls?

    Example,

    -bash-4.1# find . -type l -ls | head
    405327 0 lrwxrwxrwx 1 root root 21 Jul 15 12:25 ./gdm/Xsession -> ../X11/xinit/Xsession
    263317 0 lrwxrwxrwx 1 root root 33 Jul 15 12:58 ./skel/.xinputrc -> /etc/X11/xinit/xinput.d/ibus.conf
    261742 0 lrwxrwxrwx 1 root root 10 Oct 9 20:32 ./rc4.d -> rc.d/rc4.d
    261948 0 lrwxrwxrwx 1 root root 36 Jul 15 12:14 ./alternatives/mkisofs-mkisofsman -> /usr/share/man/man1/genisoimage.1.gz
    261949 0 lrwxrwxrwx 1 root root 20 Jul 15 12:14 ./alternatives/mkisofs-mkhybrid -> /usr/bin/genisoimage
    262127 0 lrwxrwxrwx 1 root root 33 Oct 9 20:33 ./alternatives/jre_1.6.0 -> /usr/lib/jvm/jre-1.6.0-ibm.x86_64
    262809 0 lrwxrwxrwx 1 root root 18 Oct 9 20:32 ./alternatives/print-lpc -> /usr/sbin/lpc.cups
    263444 0 lrwxrwxrwx 1 root root 32 Sep 24 00:46 ./alternatives/jaxp_parser_impl -> /usr/share/java/libgcj-4.4.6.jar
    263449 0 lrwxrwxrwx 1 root root 37 Sep 24 00:47 ./alternatives/javah -> /usr/lib/jvm/java-1.5.0-gcj/bin/javah
    263452 0 lrwxrwxrwx 1 root root 44 Sep 24 00:47 ./alternatives/appletviewer -> /usr/lib/jvm/java-1.5.0-gcj/bin/appletviewer
    -bash-4.1#

    ReplyDelete
    Replies
    1. Good One!!! Expecting this type of answers ;-)

      --
      Manoj Kumar
      http://linuxinterviewquetions.blogspot.no/2011/11/linux-interview-questions.html

      Delete
  3. It is only good for junior developers. Not good for experienced

    ReplyDelete
    Replies
    1. I agree, I would prefer more task based questions than fact based question in any UNIX or Linux Interviews. I would rather ask candidate to

      find a text in 3GB file? (based on SED command)
      finding a file which may exist in sub directory? (based on find command)
      sorted values from 5th column of a CSV file? (cut, sort, or awk command based)
      Finding how much swap space is free? (memory based)
      finding which thread from a particular process is hogging CPU(prstat command based).

      Let me know what do you think about these Linux questions?

      Delete
  4. How do you find open files for a process in Linux?
    Answer : you can either use lsof command which lists open file descriptor or you can do ls /proc/pid/fd

    ReplyDelete
  5. What is difference between ps -ef and ps -auxwww command? when to use which ps command?

    ReplyDelete
    Replies
    1. ps -auxwww gives the detailed description of active processes

      Delete
  6. normally, we use ps to get process details,, so using when you run "ps -aux" this would print details using Unix format and when we run "ps aux" this would print details in BSD format. both command would mostly perform the same job,, u would need to check the man page of "ps" for more details and use options accordingly ....

    ReplyDelete
  7. i was asked to tell the boot process in linux

    ReplyDelete
    Replies
    1. 1. BIOS(POST check)
      2. MBR(partition Information and it will execute the GRUB)
      3. GRUB (Bootloader and it will execute the kernel)
      4. Kernel (It will execute the /sbin/init)
      5. init (execute the runlevel programs)
      6. Runlevel(X-windows)

      Delete
  8. please add more on arguments handler ... passing and handling arg to shell

    ReplyDelete
  9. these question help me in my cllege placement thaks

    ReplyDelete

Feel free to comment, ask questions if you have any doubt.