Thursday, March 27, 2014

unix interview question with answer

unix interview question  Below are some list of some unix  interview question , which are commonly asked in unix interview.

1) How to print/display the last line of a file?
A) $> tail -1 file.txt
2) How to display n-th line of a file?
A) $> sed –n ' p' file.txt
3) How to remove the first line / header from a file?
A) $> sed '1 d' file.txt
4) How to remove the last line/ trailer from a file in Unix script?
A) $> sed –i '$ d' file.txt
5) How to remove certain lines from a file in Unix?
A) $> sed –i '5,7 d' file.txt
6) How to remove the last n-th line from a file?
A) $> sed –i '96,100 d' file.txt # alternative to command [head -95 file.txt]
7) How to check the length of any line in a file?
A) $> sed –n ' p' file.txt
8) How to get the nth word of a line in Unix?
A) cut –f -d' '
9) How to reverse a string in unix?
A) $> echo "unix" | rev
xinu
10) How to get the last word from a line in Unix file?
A) $>echo "C for Cat" | rev | cut -f1 -d' ' | rev
Cat
11)What are some common shells and what are their indicators?
sh – Bourne shell
csh – C SHell
bash – Bourne Again Shell
tcsh – enhanced C Shell
zsh – Z SHell
ksh – Korn SHell
12) What is a directory?
Every file is assigned to a directory. A directory is a specialized form of file that maintains a list of all files in it.
An inode is an entry created on a section of the disk set aside for a file system. The inode contains nearly all there is to know about a file, which includes the location on the disk where the file starts, the size of the file, when the file was last used, when the file was last changed, what the various read, write and execute permissions are, who owns the file, and other information.
14) You have a file called tonky in the directory honky. Later you add new material to tonky. What changes take place in the directory, inode, and file?
The directory entry is unchanged, since the name and inode number remain unchanged. In the inode file, the file size, time of last access, and time of last modification are updated. In the file itself, the new material is added.
For more good article on unix interview question with answer , pls check here.



No comments:

Post a Comment