Home |
Write |
179 members |

Join with Aptibook

Unix interview questions and answers - Page 1

1. Draw the general Hierarchy of Unix File System


2. What is Absolute and relative path names in Unix ?

Absolute Path name:
The complete path name starting from root(/).
Example: /home/training/present
Relative Pathname:
The pathname relative to current working directory.
Example: training/present

3. What are the types of commands in Unix ?

Internal Commands:
These are shell built-ins, not stored as separate files.
The shell does not generate a process for these commands and executes them directly.
Examples: cd, echo

External Commands:
These are stored as files having an independent existence.
The shell creates a process for these commands
Examples: cat, ls

Shell Scripts:
The shell executes these scripts by spawning another shell.
The child shell becomes the parent of the commands that feature in the script.
The child shell executes the commands in the script
Examples: sh scriptname

4. How to print/display the first line of a file ?

Using head command, we can display the first line.

head -1 filename.txt

For printing first "n" lines from the file, we can use
head -n filename.txt

Another way: (using sed)
sed ‘2,$ d’ file.txt

How it works ?
"d" tells sed to remove all lines from second line to the end of file ($).
So, you can see only the first line.

5. Explain date command in Unix ?

1. To print system date and time in default format.
$ date
Sat Mar 9 18:09:06 UTC 2013

2. To print only system time
$ date +%T

3. To print only system date
$ date +%D

4. To print only year value
$ date +%Y

5. To print only month name
$ date +%B