UNIX questions with answers for freshers

1) What would be the output of the following command?
$> >>xxtty
Ans: Create a new blank file xxtty

2) What would be the output of &> >> junk echo hello where junk is existing file.

Ans: append hello to file junk

3) What is the use of -m and -p options in mkdir command?
Ans : -m option directly sets the directory permission.
eg. mkdir -m 754 dirname
# sets the permission independent of system wide default permission
-p option creates multiple directories ina single go.
eg. mkdir -p a/b/c

4) What would be the difference between $> echo \\\\n and $> echo \\\\\n
Ans: Both of them print \n

5) Using grep, find blank line in a file.
Ans: grep ‘^$’ filename

6) Search either [ or ]
Ans: grep ‘[][]’ filename

7) what is the output for $> echo $_
Ans: It will display the last argument of last executed command.

8) What does the purpose of $> set -v
Ans : This command causes shell to echo each command before it executes it.It can be used while debugging a shell program by inserting the statement as the first statement of the program.

9) How to read from a file line by line in a script?
Ans: The shell script follows:
exec < filename while read line do echo $line done exec < $terminal Here the exec statement is used to redirect the standard input from a file so that the read statement reads file line by line and returns failure at the end of file. the last statement again makes the read statement to read from keyboard. 10) What is the output of $> df -ivt filename
Ans: Number of bytes = 512 * number of block occupied

11) what is the error in $> dfspace # disk free space The above command is in /etc

In order to execute we have to give $> /etc/dfspace

12) what is difference between pg and more command?
Ans: pg permits to set the prompt whereas more doesnt.

13) what is the output of $> echo \\\
$> echo \\\
> # continues on next line

14) What does the following command do?
chmod 1754 filename
Ans: 754 will set the file permissions and 1 is used to set sticky bit.

15) what is the output of $> ls -l | grep d*

Ans: same as ls -l

If you have questions, please ask below

Leave a Reply

If you have any questions headover to our forums

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>