Wednesday, September 19, 2012

10 Linux and UNIX Interview Questions and Answers asked in Wipro TCS Capegemini

UNIX and Linux Interview Questions and Answers
Questions from various UNIX operating systems e.g. Solaris, Linux, IBM AIX or any other UNIX operating system is asked on different support and programming interviews. I have always seen few interview questions from Linux and UNIX along with SQL in almost every Java programming interviews. You just can not afford not to prepare questions from UNIX and Linux until your Job absolutely doesn't require any work in UNIX operating system. I have collected many UNIX command interview questions and already shared them but I found that except system admin jobs, many programming job interviews only focus on general UNIX commands e.g. 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 kind of frequently asked interview questions and answers from UNIX and Linux operating System. Questions are very fundamental in nature and not limited to Linux only and equally applicable to other UNIX operating systems e.g. Solaris, IBM AIX etc. Many of these UNIX questions are asked during various interviews on companies like TCS, Infosys, Citibank , Wipro, Capegemini and Tech Mahindra. But as I said they are very fundamental and can be asked in any company.

UNIX and Linux Interview questions answers

Linux command interview questions and answers for programmersHere is my list of frequently asked UNIX and Linux interview questions and answers. All these questions are based upon fundamental commands and concepts which is must for working in 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 ln command for creating and updating soft links but nothing which gives you all the links in a directory. You need to use ls command which list everything in directory and then you need to list all the links, as they starts with "l" as first characters, as shown in 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 questions. Answer of this question is simple if you are familiar with ps, grep and kill command. by using "ps -ef" you can get list of all process and then use grep to find your process and get the PID of that process. Once you got PID you can use kill command to kill that process as shown in this example of kill command in UNIX.


3) How to run a program in background in UNIX or Linux ?
an easy UNIX or Linux interview question, only when you know. You can use & to run any process in background and than you can use jobs to find the job id for that process and can use  fg and bg command to bring that process into foreground and background.

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

5) How to create archive file in UNIX or Linux Operating System ?
Another interview question based on knowledge of UNIX or Linux command. you can use 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 meaning of a file has 644 permission ?
To answer this UNIX or Linux interview question, you must know basics of files and directories in UNIX.  644 represents permission 110 for owner, permission 100 for group and 100 for others which means read + write for owner who create that file and read only permission for group and others. See this tutorial on UNIX file permission for more details.

7) How will you remove empty files or directories from /tmp ?
See how to delete empty directory and files in UNIX to answer this UNIX command interview questions.

8) I have read permission on a directory but I am not able to enter it why ?
One more tricky UNIX questions. In order to get into a directory you need execute permission. if your directory does not have execute permission than you can not go into that directory by using 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 the Linux interview questions from frequently used command e.g. find and grep. you can use -mtime option of 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 to do you find size of directory in UNIX or Linux ?
This is another tricky and bit tough Linux interview question as popular ls command doesn't show complete size of directories in UNIX. you need to use du command to get full size of directories including all sub directories in UNIX. See How to find directory size in UNIX for exact command and detailed explanation.

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 e.g. core Java and J2EE interviews. Questions from UNIX and Linux is also very popular during C and C++ programming interviews.

5 comments:

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

    ReplyDelete
  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

Java67 Headline Animator