You are on page 1of 14

UNIX command Questions Answers asked in Interview

UNIX or Linux operating system has become default Server operating system and for whichever programming job you give interview you find some UNIX command interview questions there. These UNIX command interview questions are mostly asked during ava development and Support role interviews on various investment banks mostly because most of electronic trading systems or stock trading system works on Uni! servers. "s we know that high volume low latency systems which wants to take advantage of little bit of volatility in market for #quity $ %utures and options or %oreign e!change trading need a stable server side operating system and &edhat 'inu! is doing great job there. with the advent of"lgorithmic trading this speed factor becomes more important so getting someone who has good knowledge of operating system and commands on which these trading system runs is definitely required. but these UNIX command interview questions are equally applicable for any job interview which requires some work on Uni! (perating System. )ith the growing use of 'inu! in form of &ed*at$ Solaris and I+, "IX its must to keep you familiar with essential 'inu! commands available on various platforms.

'ong back I had once asked one of my friend why are you preparing Uni! -ommand interview questions if you going for a ava Interview and he told me that this job doesn.t only require knowledge of ava but also knowledge of Uni!$ 'inu!$ S/' and other scripting language $ which is quite true. "fter that I thought to collect various UNIX command interview questions asked to ava developers or trading system support interviews and this is the result of that compilation. 0his list of UNIX command interview questions are by means complete and would be great if you guys contribute some genuine and good Unix Command Interview questions and answers asked during interviews. I have divided the questions on three categories for sake of managing and keeping this list of Uni! Interview questions up to date.

Beginners UNIX Interview Questions Answers


1. rite command to list all the lin!s "rom a directory#

In this UNIX command interview questions interviewer is generally checking whether user knows basic use of 1ls1 1grep1 and regular e!pression etc 2ou can write command like3 ls 4lrt 5 grep 16l1

$. Create a read%only "ile in your home directory#

0his is a simple UNIX command interview questions where you need to create a file and change its parameter to read4only by using chmod command you can also change your umask to create read only file. touch file chmod 788 file

read more about file and directory permission in unix and linux here.
&. 'ow will you "ind which operating system your system is running on in UNIX# +y using command (uname %a( in UNIX

). 'ow will you run a process in *ac!ground# 'ow will you *ring that into "oreground and how will you !ill that process# %or running a process in background use 191 in command line. %or bringing it back in foreground use command 1 "g +o*id( and for getting job id you use command 1jobs1$ for killing that process find :I; and use kill 4< :I; command. 0his is indeed a good Uni! -ommand interview questions because many of programmer not familiar with background process in UNIX.

,. 'ow do you !now i" a remote host is alive or not# 2ou can check these by using either ping or telnet command in UNIX. 0his question is most asked in various Uni! command Interview because its most basic networking test anybody wants to do it.

-. 'ow do you see command line history in UNIX# =ery useful indeed$ use history command along with grep command in unix to find any relevant command you have already e!ecuted. :urpose of this Uni! -ommand Interview /uestions is probably to check how familiar candidate is from available tools in UNIX operation system.

.. 'ow do you copy "ile "rom one host to other# ,any options but you can say by using 1scp1 command. 2ou can also use rsync command to answer this UNIX interview question or even s"tp would be ok.

/. 'ow do you "ind which process is ta!ing how much C0U# +y using 1top1 command in UNIX$ there could be multiple follow4up UNIX command interview questions based upon response of this because >0(:? command has various interactive options to sort result based upon various parameter.

1. 'ow do you chec! how much space le"t in current drive #

+y using (d"( command in UNIX. %or e!ample (d" %h .( will list how full your current drive is. 0his is part of anyone day to day activity so I think this Uni! Interview question will be to check anyone who claims to working in UNIX but not really working on it.

12.

hat is the di""erence *etween 3wapping and 0aging#

Swapping3 )hole process is moved from the swap device to the main memory for e!ecution. :rocess si@e must be less than or equal to the available main memory. It is easier to implementation and overhead to the system. Swapping systems does not handle the memory more fle!ibly as compared to the paging systems. :aging3 (nly the required memory pages are moved to main memory from the swap device for e!ecution. :rocess si@e does not matter. Aives the concept of the virtual memory. It provides greater fle!ibility in mapping the virtual address space into the physical memory of the machine. "llows more number of processes to fit in the main memory simultaneously. "llows the greater process si@e than the available physical memory. ;emand paging systems handle the memory more fle!ibly.

Intermediate UNIX Interview Questions Answers


1. hat is di""erence *etween ps %e" and ps %auxwww#

0his is indeed a good Uni! Interview -ommand /uestion and I have faced this issue while ago where one culprit process was not visible by e!ecute ps 4e" command and we are wondering which process is holding the file. ps 4ef will omit process with very long command line while ps 4au!www will list those process as well.

$. 'ow do you "ind how many cpu are in your system and there details# +y looking into file BetcBcpuinfo for e!ample you can use below command3 cat 5proc5cpuin"o

&.

hat is di""erence *etween 'ardLin! and 3o"tLin! in UNIX#

I have discussed this Uni! -ommand Interview questions in my blog post difference between Soft link and *ard link in Uni!

).

hat is 6om*ie process in UNIX# 'ow do you "ind 6om*ie process in UNIX#

)hen a program forks and the child finishes before the parent$ the kernel still keeps some of its information about the child in case the parent might need it 4 for e!ample$ the parent may need to check the child.s e!it status. 0o be able to get this information$ the parent calls .waitCD.E In the interval between the child terminating and the parent calling .waitCD.$ the child is said to be a .@ombie. CIf you do .ps.$ the child will have a .F. in its status field to indicate this.D 6om*ie 7 The process is dead *ut have not *een removed "rom the process ta*le.

,.

hat is (chmod( command#

hat do you understand *y this line 8r%% %w% %%x#

-. There is a "ile some where in your system which contains word (UnixCommandInterview9uestions: 'ow will "ind that "ile in Unix# +y using find command in UNIX for details see here G8 e!ample of using find command in Uni!

.. In a "ile word UNIX is appearing many times# 'ow will you count num*er# grep 4c 1Uni!1 filename

/. 'ow do you set environment varia*le which will *e accessi*le "orm su* shell# +y using export for e!ample e!port countHG will be available on all sub shell.

1. 'ow do you chec! i" a particular process is listening on a particular port on remote host# +y using telnet command for e!ample >telnet hostname port?$ if it able to successfully connect then some process is listening on that port. 0o read more about telnet read networking command in UNIX

12. 'ow do you "ind whether your system is &$ *it or -) *it # #ither by using (uname %a( command or by using 1arch1 command.

Advanced UNIX Interview Questions and Answers


1. 'ow do you "ind which processes are using a particular "ile#

+y using lso"command in UNIX. It wills list down :I; of all the process which is using a particular file.

$. 'ow do you "ind which remote hosts are connecting to your host on a particular port say 121$&# +y using netstat command e!ecute netstat 4a 5 grep 1port1 and it will list the entire host which is connected to this host on port G8GIJ.

&.

hat is nohup in UNIX#

).

hat is ephemeral port in UNIX#

#phemeral ports are port used by (perating system for client sockets. 0here is a specific range on which (S can open any port specified by ephemeral port range.

,. I" one process is inserting data into your ;y39L data*ase# 'ow will you chec! how many rows inserted into every second# :urpose of this Uni! -ommand Interview is asking about (watch( command in UNIX which is repeatedly e!ecute command provided with specified delay.

-. There is a "ile Unix<Test.txt which contains words Unix= how will you replace all Unix to UNIX# 2ou can answer this Uni! -ommand Interview question by using S#; command in UNIX for e!ample you can e!ecute sed s5Unix5UNIX5g "ileName.

.. >ou have a ta* separated "ile which contains Name= ?ddress and 0hone Num*er= list down all 0hone Num*er without there name and ?ddresses# 0o answer this Uni! -ommand Interview question you can either you ")K or -U0 command here. -U0 use tab as default separator so you can use cut %"& "ilename.

/. >our application home directory is "ull# 'ow will you "ind which directory is ta!ing how much space# +y using disk usage C;UD command in Uni! for e!ample du 4sh . @ grep A will list down all the directory which has AIAS in Si@e.

1. 'ow do you "ind "or how many days your 3erver is up# +y using uptime command in UNIX

12. >ou have an I0 address in your networ! how will you "ind hostname and vice versa#

0his is a standard UNIX command interview question asked by everybody and I guess everybody knows its answer as well. +y using nsloo!up command in UNIX$ you can read more about Convert I0 ?ddress to hostname in Unix here.

I hope this UNIX command interview questions and answers would be useful for quick glance before going for any UNIX or ava job interview. :lease share any interesting UNIX command interview you have come across and I will add into this list. If you are going for any Uni! interview on brokerage firm or stock trading company or any Investment bank you can have a quick look here$ though most of questions you might already know but its good to review it. if you like this you can see my other uni! command tutorial for beginners as well

10 xamples of tar command in UNIX and !inux


tar command in UNIX or 'inu! is one of the important command which provides archiving functionality in uni!. we can use UNIX tar command to create compressed or uncompressed archive files by using either g@ip or b@ipI. In this unix tar command tutorial we will see e!amples of uni! tar command related to basic archiving task e.g. 'ow to create tar archive in Unix and Linux $ *ow to e!tract files from tar archive in uni!$ *ow to view contents of tar file in Uni! and 'inu! or how to update and e!isting tar file in Uni!. #!amples of tar command in uni! are kept simple and easy to understand and master each of basic task using unix tar command. I thought about this article when I written how to be productive in UNIX and UNIX command tutorial and #!ample for beginners but somehow it gets delayed and now I am happy to see this published. (k enough introduction now let.s see some real life examples of tar command in Unix and Linux 3

"ow to use tar command in Unix

Using tar command in UNIX is simple and it has similar synta! like any other UNIX command. below is the synta! of tar command in UNIX3

tar

[options] [name of tar file to be created] [list of files and directories to be

included]

0his syntax o" tar command is for easy understanding you can also check detailed synta! by using command 1tar 44usage1 in uni! machine.

tar command examples in !inux


Unix tar command line options 444444444444444444444444444444444444444 In this section of UNIX tar command tutorial we will see some useful options of tar command in 'inu! and we will use this options on our e!ample to understand usage of this option along4with tar command.

c 44 create$ for creating tar file v 44 verbose$ display name of files including$e!cluding from tar command f 44 following$ used to point name of tar file to be created. it actually tells tar command that name of the file is 1ne!t1 letter just after options.

! 44 e!tract$ for e!tracting files from tar file. t 44 for viewing content of tar file @ 44 @ip$ tells tar command that create tar file using g@ip. j L4 another compressing option tells tar command to use b@ipI for compression r 44 update or add file or directory in already e!isted .tar file wildcards 44 to specify patters in uni! tar command

'ow to create tar archive or tar "ile in Unix 4444444444444444444444444444444444444444444444444444444 ,ost of use use either win@ip or winrar in windows machine to @ipping or creating archives of content so when we move to command line interface like Uni! or 'inu! we struggle without those tools. UNIX

tar command is similar to win@ip or winrar and you can use UNIX tar command to create both compressed or uncompressed C@ippedD archives in UNIX.

In this e!ample of tar command we will create tar file including all the files and directories or selected files and directories in Uni!.

here is our directory

stock_trader@system:~/test ls -lrt total 0 -r--r--r-1 stock_trader Domain Users 0 ul 1! 11:"# e$uity ul 1! 1":(( stocks/ ul 1! 1!:(0 currency

dr%&r%&r%&' 1 stock_trader Domain Users 0 -r--r--r-1 stock_trader Domain Users 0

it has two files and one directory. now we will create a tar file with all these contents.

stock_trader@system:~/test tar -cvf trading.tar * currency e$uity stocks/ stocks/online_stock_e&c)an*es+t&t

2ou see uni! tar command is creating tar file with name 1trading1 with contents shown above. just to review here 14c1 is used to create tar file 1v1 is used to be verbose and 1f1 is used to tell tar file name. 2ou can see the tar file here

stock_trader@system:~/test ls -lrt -r--r--r-1 stock_trader Domain Users 0 0 0 ul 1! 11:"# e$uity ul 1! 1":(( stocks/ ul 1! 1!:(0 currency ul 1- 1#:#. tradin*+tar

dr%&r%&r%&' 1 stock_trader Domain Users -r--r--r--r%-r--r-1 stock_trader Domain Users

1 stock_trader Domain Users 10,

'ow to view contents o" tar "ile in Unix or Linux 4444444444444444444444444444444444444444444444444444444444444

In earlier e!ample of tar command in Uni! or 'inu! we have created a uncompressed tar file called 1trading.tar1 now in this e!ample we will see the actual content of that tar file.

stock_trader@system:~/test tar -tvf trading.tar -r--r--r-- stock_trader/Domain Users 0 #011-0/-1! 1!:(0 currency -r--r--r-- stock_trader/Domain Users 0 #011-0/-1! 11:"# e$uity dr%&r%&r%& stock_trader/Domain Users 0 #011-0/-1! 1":(( stocks/ -r%&r%&r%& stock_trader/Domain Users 0 #011-0/-1! 1":(( stocks/online_stock_e&c)an*es+t&t

here option 1t1 is used to display content of tar file in uni! while options 1v1 and 1f1 are for 1verbose1 and 1following1. now you can clearly see that all the files which we wanted to be included in tar file are there.

'ow to extract contents "rom a tar "ile in Unix 44444444444444444444444444444444444444444444444444444444444 In this e!ample of uni! tar command we will see how to e!tract files or directories from a tar file in uni! or 'inu!. )e will use same trading.tar file created in earlier e!ample. In this e!ample we will create a directory 1trading1 and e!tract contents of trading.tar on that directory.

stock_trader@system:~/test/ne% ls -lrt total 1#, -r%-r--r-- 1 stock_trader Domain Users 10, ul 1- 1#:(/ tradin*+tar

Now the directory is empty just trading.tar file

stock_trader@system:~/test/ne% tar -xvf trading.tar currency e$uity stocks/ stocks/online_stock_e&c)an*es+t&t

0his uni! tar command will e!tract content of trading.tar in current directory. 1!1 is used for e!tracting. 1v1 is again for verbose and optional parameter in all our e!ample.

stock_trader@system:~/test/ne% ls -lrt -r--r--r-1 stock_trader Domain Users 0 0 0 ul 1! 11:"# e$uity ul 1! 1":(( stocks/ ul 1! 1!:(0 currency ul 1- 1#:(/ tradin*+tar

dr%&r-&r-&' 1 stock_trader Domain Users -r--r--r--r%-r--r-1 stock_trader Domain Users

1 stock_trader Domain Users 10,

Now you can see that all the files and directories which were included in tar file Cstocks$ equity and currencyD has been e!tracted successfully.

'ow to create tar "ile in Unix with +ust speci"ied contents 4444444444444444444444444444444444444444444444444444444444444444444444444 In above e!ample of tar command in uni! we have created tar file with all the contents available in current directory but we can also create tar file with selective content as shown in above e!ample.

Now in our current directory we have both files and directories and we just want to include two files equity and currency in our tar file.

stock_trader@system:~/test ls -lrt -r--r--r-1 stock_trader Domain Users 0 0 0 ul 1! 11:"# e$uity ul 1! 1":(( stocks/ ul 1! 1!:(0 currency ul 1- 1#:#. tradin*+tar ul 1- 1#:"0 ne%/

dr%&r%&r%&' 1 stock_trader Domain Users -r--r--r--r%-r--r-1 stock_trader Domain Users

1 stock_trader Domain Users 10, 0

dr%&r-&r-&' 1 stock_trader Domain Users

stock_trader@system:~/test tar -cvf equitytrading.tar equity currency e$uity currency

you see only two files equity and currency are included in our tar file.

'ow to create compressed tar "ile using gBip in Unix 444444444444444444444444444444444444444444444444444444444444444444

In our previous e!ample of 'inu! tar command we have created uncompressed tar file but most of the time we also need to create compressed tar file using g@ip or b@ipI. In this e!ample of tar command in

'inu! we will learn about creating tar file using g@ip.


stock_trader@system:~/test tar -zcvf trading.tgz * currency e$uity stocks/ stocks/online_stock_e&c)an*es+t&t

you see creating tar file with g@ip is very easy just use 14@1 option and it will crate a g@ip tar. .tg@ or tar.g@ e!tension is used to denote tar file with g@ip. si@e of a compressed tar file is far less than uncompressed one.

stock_trader@system:~/test ls -lrt -r--r--r-1 stock_trader Domain Users 0 0 0 ul 1! 11:"# e$uity ul 1! 1":(( stocks/ ul 1! 1!:(0 currency ul 1- 1(:01 tradin*+t*1

dr%&r%&r%&' 1 stock_trader Domain Users -r--r--r--r%-r--r-1 stock_trader Domain Users

1 stock_trader Domain Users #1.

you can also view contents of g@ip tar file by using earlier command in combination of 1@1 option and same is true for e!tracting content from g@ip tar. below e!amples of uni! tar command will show how to view contents of .tg@ or .tar.g@ file in uni!.

stock_trader@system:~/test tar -ztvf trading.tgz -r--r--r-- stock_trader/Domain Users 0 #011-0/-1! 1!:(0 currency -r--r--r-- stock_trader/Domain Users 0 #011-0/-1! 11:"# e$uity dr%&r%&r%& stock_trader/Domain Users 0 #011-0/-1! 1":(( stocks/ -r%&r%&r%& stock_trader/Domain Users 0 #011-0/-1! 1":(( stocks/online_stock_e&c)an*es+t&t

Similarly we can e!tract contents from a .tgB or .tar.gB "ile as shown in below e!ample of uni! tar command 3

stock_trader@system:~/test/ne% tar -zxvf trading.tgz currency

e$uity stocks/ stocks/online_stock_e&c)an*es+t&t

stock_trader@system:~/test/ne% ls -lrt -r--r--r-1 stock_trader Domain Users 0 0 0 ul 1! 11:"# e$uity ul 1! 1":(( stocks/ ul 1! 1!:(0 currency ul 1- 1(:0/ tradin*+t*1

dr%&r-&r-&' 1 stock_trader Domain Users -r--r--r--r%-r--r-1 stock_trader Domain Users

1 stock_trader Domain Users #1.

'ow to create compressed tar "ile using *Bip$ in Unix 44444444444444444444444444444444444444444444444444444444444444444444 b@ipI is another compression option we have which we can use with uni! tar command. its e!actly similar with our earlier option of compressing using g@ip but instead of 1@1 option we need to use 1j1 tar option to create b@ipI file as shown in below e!ample of tar command in uni!.

stock_trader@system:~/test tar -jcvf trading.tar.bz2 2 currency e$uity stocks/ stocks/online_stock_e&c)an*es+t&t

stock_trader@system:~/test ls -lrt trading.tar.bz2 -r%-r--r-1 stock_trader Domain Users !.( ul 1- 1(:11 tradin*+tar+b1#

.tar.b@I is used to denote a tar file with b@ipI compression. for viewing contents of b@ipI tar file and e!tracting content we can use as shown in example of UNIX tar command with g@ip compression$ just replace 14@1 with 14j1 for b@ipI.

'ow to extract a particular "ile "orm .tar= .tar.gB or .tar.*Bip$ 4444444444444444444444444444444444444444444444444444444444444444444444444444

In previous e!amples of e!tracting contetns from tar file we have e!tracted everything. sometime we just need a specific file from tar file. in this e!ample of uni! tar command we will e!tract a particular file from a tar archive.

stock_trader@system:~/test/ne% tar -jxvf trading.tar.bz2 equity e$uity

its simple just specify name of file in this case its 1equity1. if your tar file is g@ip one then use 14@1 that.s it. 2ou can also use combination of grep and find command with tar to get more dynamic use.

'ow to extract group o" "ile or directory "rom "orm .tar= .tar.gB or .tar.*Bip$ in UNIX %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% you can e!tract a group of file form .tar$ .tar.g@ or .tar.b@ipI in Uni! by specifying a matching pattern and using option 144wildcards1. let.s an e!ample of tar command in uni! with 44wildcards

stock_trader@system:~/test/ne% tar -jxvf trading.tar.bz2 --wildcards "s*" stocks/ stocks/online_stock_e&c)an*es+t&t

In above e!ample of UNIX tar command we are e!tracting all files or directory which names starts with 1s1.

'ow to update existing tar "ile in Linux %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2ou can also update or append new files in already created tar file. option14r1 is used for that. 'etMs see an e!ample of updatating tar file using tar command in UNIX3

stock_trader@system:~/test tar -cvf sample.tar equity currency e$uity currency

stock_trader@system:~/test tar -rvf sample.tar gold *old

stock_trader@system:~/test tar -t3f sample+tar -r--r--r-- stock_trader/Domain Users 0 #011-0/-1! 11:"# e$uity -r--r--r-- stock_trader/Domain Users ##1 #011-0/-1- 1(:10 currency -r%-r--r-- stock_trader/Domain Users 0 #011-0/-1- 1(:(0 *old

"pparently can not update compressed archives.if you try to do you will get error (tar7 Cannot update compressed archives(

Calculating siBe o" tar "ile in UNIX 4444444444444444444444444444444444444444444 Some time its useful to know the si@e of tar file before creating it and you can get it by using uni! tar command as shown in below e!ample3

stock_trader@system:~/test tar -cf - * | wc -c #0"-0

Si@e shown here is in K+ and you can also calculate si@e for compressed tar file by using 1@1 for g@ip and 1j1 for b@ipI

You might also like