Wednesday, December 28, 2011

UNIX interview questions

Q: What is the difference between vi and emacs editor?
Ans: vi is a modaleditor whereas emacs is not. That is in vi editor you have edit mode and command mode whereas in emacs only one mode. For more details visit vi editor.

Q: UNIX is case sensitive. To avoid this issue with case sensitive what option you can use while searching for a pattern?
Ans:
grep 'Phoenix' *.txt may give you output, whereas grep 'PHOENIX' *.txt may not.
To avoid this case sensitivity use the option 'i'
grep -i 'PHOENIX' *.txt

Q: What is meant by a filter in UNIX?
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.

Q: What is the significance of tee command?
Ans:
A powerful command that reads the standard input and sends it to standard output while redirecting a copy to a file specified. It is just re-route the pipline with tee.

Q: What is the significance of awk command?
Ans:
Helps you grab specific columns of information, modify text as it follow past, and swap the order of column information in a file.

Helps in analyzing and manipulating text files. Another alternative for this is the sed command which is less powerful compared to awk command.

Q: What does the command “ $who | sort –logfile > newfile” do?
Ans: This example explains the tricky use of hyphen (-). Above code gives the output from who command as input for sort command, meanwhile sort command will open the file called logfile and the content of this file is sorted togehter with the output of who and moving that to the file called newfile.

Q: What does the command “$ls | wc –l > file1” do?
Ans: Here ls is the input for the command wc and takes the count of line from ls and the count of lines is stored into file1 instead of displaying in the monitor.

Q: Which of the following commands is not a filter man , (b) cat , (c) pg , (d) head
Ans:
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.
Q: What is the difference between the redirection operators > and >>?
Ans:
When redirection operator > overwrite the content of file >> operator appends to file.

Q: Explain the steps that a shell follows while processing a command.
Ans:
Below are the steps followed by shell

Parsing: Shell first breaks up the command line into words, using spaces and delimiters, unless quoted. All consecutive spaces or tabs are replaces with single space.

Variable Evaluation: All words preceded by a $ are evaluated as variables, unless quoted or escaped.

Command Substitution:Any commands surrounded by backquotes is executed by the shell which then replaces the standard output of the command into the command line.

Wild Card Interpretation: The shell finally scans the command line for the wildcard characters (*,.,?,[,]). Any word containing a wild card is replaced by a sorted list of fienames that match the pattern. The list of this filenames then become the argument to the command.

PATH Evaluation:
It finally looks for the PATH variable to determine the sequence of directories it has to search in order to hunt for the command.

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

Q: What is the difference between cat and more command?
Ans:
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.

Q: Write a command to kill the last background job?
Ans:
Kill $!

Q: Which command is used to delete all files in current directory and all its sub-directories?
Ans:
rm -r *

Q: Write a command to display a file’s contents in various formats?
Ans:
$od -cbd file_name

c - character, b - binary (octal), d-decimal, od=Octal Dump.

Q: What will the following command do/
$echo *
Ans;
It is similar to ls command, list down all the files in the current directory.

Q: Is it possible to create a new file system in UNIX?
Ans: Yes, 'mkfs' is used to create a new file system.

Q: Is it possible to restrict the incoming message?
Ans: Yes, using the 'mesg' command

Q:What is the use of the command "ls -x chapter[1-5]"?
ls stands for list; so it displays the list of the files that starts with 'chapter' with suffix '1' to '5', chapter1, chapter2, and so on.

Q: Is ‘du’ a command? If so, what is its use?
Ans:
Yes, it stands for ‘disk usage’. With the help of this command you can find the disk capacity and free space
of the disk.
Q: Is it possible to count number char, line in a file; if so, How?
Ans:
Yes, wc-stands for word count.
wc -c for counting number of characters in a file.
wc -l for counting lines in a file.

Q: Name the data structure used to maintain file identification?
Ans:
inode, each file has a separate inode and a unique inode number.

Q: How many prompts are available in a UNIX system?
Ans:
Two prompts, PS1 (Primary Prompt), PS2 (Secondary Prompt).

Q. How does the kernel differentiate device files and ordinary files?
Kernel checks 'type' field in the file's inode structure.


***
Hope this is helpful. Thanks Phoenix.

2 comments:

  1. Hi Shiyas C M,

    So bloody thorough! Ah! So happy and blissed out! I feel redeemed by reading out #topic. Keep up the good work!

    Is is true the number of people with Unix skills is really declining?
    A lot of Microservices, serverless computing bandwagon is seen on the market, does it means Unix/Linux and servers will be non-existent in future?

    Super likes !!! for this amazing post. I thinks everyone should bookmark this.

    Ciao,
    Irene Hynes

    ReplyDelete
  2. Hi Shiyas,

    Your blog is such a complete read. I like your approach with A2Z on Tech. Clearly, you wrote it to make learning a cake walk for me.

    I think you should have a quick look at Unix article this something that helps me all the time?

    By the way do you have any YouTube videos, would love to watch it. I would like to connect you on LinkedIn, great to have experts like you in my connection (In case, if you don’t have any issues).


    Thank you,
    Abhiram

    ReplyDelete