Sunday, May 19, 2013

UNIX Commands Interview Questions!!!

If EMP table is saved as EMP.txt then how to find the Unique salary?

                       cat EMP.txt | cut -f3 -d "|" | sort -u       [also uniq -u  can be used]

How to find the record for EMP_ID=100 ?
 
                       cat EMP.txt | awk 'BEGIN {FS="|"} {if($1==100) print $0}'

How to run a command at back end so that it will run even if the session is closed or   logged out?
          
The command nohup can be used to achieve the same. For example,
    
                       nohup find -name '*' -size +1000k > log.txt

Explain the following commands.
$ ls > file1
$ banner hi-fi > message
$ cat par.3 par.4 par.5 >> report
$ cat file1>file1
$ date ; who
$ date ; who > logfile
$ (date ; who) > logfile

What is the significance of the “tee” command?
It reads the standard input and sends it to the standard output while redirecting a copy of what it has read to the file specified by the user.

What does the command “ $who | sort –logfile > newfile” do?
The input from a pipe can be combined with the input from a file . The trick is to use the special symbol “-“ (a hyphen) for those commands that recognize the hyphen as std input.
In the above command the output from who becomes the std input to sort , meanwhile sort opens the file logfile, the contents of this file is sorted together with the output of who (rep by the hyphen) and the sorted output is redirected to the file newfile.

What does the command “$ls | wc –l > file1” do?
ls becomes the input to wc which counts the number of lines it receives as input and instead of displaying this count , the value is stored in file1.

Which of the following commands is not a filter man , (b) cat , (c) pg , (d) head
Ans: man
A filter is a program which can receive a flow of data from std input, process (or filter) it and send the result to the std output.

 What difference between cmp and diff commands?
cmp - Compares two files byte by byte and displays the first mismatch
diff - tells the changes to be made to make the files identical

What is the use of ‘grep’ command?
‘grep’ is a pattern search command. It searches for the pattern, specified in the command line with appropriate option, in a file(s).

Example : grep 99mx file_name

What is the difference between cat and more command?
Cat displays file contents. If the file is large the contents scroll off the screen before we view it. So command 'more' is like a pager which displays the contents page by page.

No comments:

Post a Comment