We have moved to www.dataGenX.net, Keep Learning with us.

Saturday, September 29, 2012

Interview Questions : Linux/Unix : Part - 4

1) What is piping?
Piping, represented by the pipe character “|”, is used to combine two or more commands together. The output of the first command serves as input the next command, and so on.

2) What is a superuser?
A superuser is a special type user who has open access to all files and commands on a system. Note that the superuser’s login is usually root, and is protected by a so-called root password.

3) How do you determine and set the path in UNIX?
Each time you enter a command, a variable named PATH or path will define in which directory the shell will search for that command. In cases wherein an error message was returned, the reason maybe that the command was not in your path, or that the command itself does not exist. You can also manually set the path using the “set path = [directory path]” command.

4) Is it possible to see information about a process while it is being executed?
Every process is uniquely identified by a process identifier. It is possible to view details and status regarding a process by using the ps command.

5) What is the standard convention being followed when naming files in UNIX?
One important rule when naming files is that characters that have special meaning are not allowed, such as * / & and %. A directory, being a special type of file, follows the same naming convention as that of files. Letters and numbers are used, along with characters like underscore and dot characters.

6) Why is it that it is not advisable to use root as the default login?
The root account is very important, and with abusive usage, can easily lead to system damage. That’s because safeguards that normally apply to user accounts are not applicable to the root account.

7) What is the use of the tee command?
The tee command does two things: one is to get data from the standard input and send it to standard output; the second is that it redirects a copy of that input data into a file that was specified.

8) Differentiate cat command from more command.
When using the cat command to display file contents, large data that does not fit on the screen would scroll off without pausing, therefore making it difficult to view. On the other hand, using the more command is more appropriate in such cases because it will display file contents one screen page at a time.

9) What is parsing?
Parsing is the process of breaking up of a command line into words. This is made possible by using delimiters and spaces. In the event that tabs or multiple spaces are part of the command, these are eventually replaced by a single space.

10) What is pid?
Pid is short for Process ID. It is used primarily to identify every process that runs on the UNIX system, whether it runs on the foreground or runs at the background. Every pid is considered unique.

11) How does the system know where one command ends and another begins?
Normally, the newline character, which is generated by the ENTER or RETURN key, acts as the signpost. However, the semicolon and the ampersand characters can also serve as command terminators.

12) What is wild-card interpretation?
When a command line contains wild-card characters such as ‘*’ or ‘?’, these are replaced by the shell with a sorted list of files whose pattern matches the input command. Wild-card characters are used to setup a list of files for processing, instead of having it specified one at a time.

13) What is the output of this command? $who | sort –logfile > newfile
In this command, the output from the command “who” becomes the input to the “sort” command. At the same time, “sort” opens logfile, arranges it together with the output from the command “who”, and places the final sorted output to the file newfile.

14) How do you switch from any user type to a super user type?
In order to switch from any user type to a superuser, you use the su command. However, you will be asked to key in the correct superuser password before full access privileges are granted to you.

15) What would be the effect of changing the value of PATH to:
.:/usr/della/bin: /bin: /usr/bin
This would cause the shell to look in the /usr/della/bin directory after looking in the current directory and before looking in the /bin directory when searching for a command file.

16) Write a command that will display files in the current directory, in a colored, long format.
Answer: ls -l –color

17) Write a command that will find all text files in a directory such that it does not contain the word “amazing” in any form (that is, it must include the words Amazing, AMAZING, or aMAZINg)
Answer: grep –vi amazing *.txt

18) Write a command that will output the sorted contents of a file named IN.TXT and place the output in another file named OUT.TXT, while at the same time excluding duplicate entries.
Answer: sort IN.TXT | uniq > OUT.TXT

19) Write a command that will allow a UNIX system to shut down in 15 minutes, after which it will perform a reboot.
Answer: /sbin/shutdown –r +10

20) What command will change your prompt to MYPROMPT: ?
To change a prompt, we use the PS1 command, such as this:

21) What does this command do? cat food 1 > kitty
Answer: it redirects the output of cat food into the file kitty; the command is the same as:
cat food > kitty

22) What is wrong with this interactive shell script?
echo What month is this?
read $month
echo $month is as good a month as any.
Answer: Initially, the question mark should be escaped (\?) so that it is not interpreted as a shell metacharacter. Second, it should be read month, not read $month.

23) Write a shell script that requests the user’s age and then echoes it, along with some suitable comment.
echo Hello! What\’s your age\?
read age
echo $age! I\’ll be obsolete by that age!

njoy the simplicity.......
Atul Singh

No comments :

Post a Comment