You are on page 1of 27

Unix Question Bank / FAQs This is a mock Exam for the Unix programmers.

It is created by Genesis InSoft Li mited (admin@genesisinsoft.com) and may be freely distributed so long as it is u nmodified. Please email us if you have any corrections or comments. Question1 All Unix commands Must be in lower case Must be in upper case Must be in mixed case letters All of the above Answer to Question 1 Question 2 Unix operating system cannot run on which of the following Microprocessor? 8086 80286 80386 Pentium Answer to Question 2 Question 3 Unix is Single user Multi-user Multitasking operating system Both B and C Answer to Question 3 Question 4 Which command is used for searching a given pattern in a file? Lookup Grep Find Search Answer to Question 4 Question 5 In which language Unix is written Perl language C language Pascal language None of the above Answer to Question 5 Question 6 Which of the following is a filter command? ls

who cat find Answer to Question 6 Question 7 The bin directory contains Binary files Executable files for most of the Unix commands General application files None of the above Answer to Question 7 Question 8 Directory /dev contains user related files device related files command file temporary files Answer to Question 8 Question 9 Which of the following is true above Unix File System? It has a hierarchical file structure Files have access permissions All devices are implemented as files All of the above Answer to Question 9 Question 10 By default what are permissions given to the user when a file is created read write read and write None of the above Answer to Question 10 Question 11 Which of the following can be used for creating a file touch cat vi All of the above Answer to Question 11 Question 12 Identify the false statement about 'ln' When a file has two links, it is not physically present at two places, but can b

e referred by either of the names When a file has two links, it is physically present at two places, but can be re ferred by either of the names By default a file has one link By default a directory has two links Answer to Question 12 Question 13 The existing permissions of file can be changed by The super user The owner or group Others All of the above Answer to Question 13 Question 14 The exit status of Grep if it fails to find a match false true null None of the above Answer to Question 14 Question 15 Shell recognizes three types of commands external commands shell scripts internal commands All of the above Answer to Question 15 Question 16 Choose the correct option to create file "middle" consisting of keyword input sa ndwiched between the contents of two files start and end Cat start Cat start Cat start Cat start Answer to end - > middle - end < middle end - < middle - end > middle Question 16

Question 17 The correct way to send date and contents of file called "results" to file "fina l" is date ; cat results > final date cat results > final (date ; cat results) > final (date, cat results) > final Answer to Question 17 Question 18

cp first second 2 > msg Errors are stored in file msg Syntax error Error message is printed on screen Contents of first and second are stored in msg Answer to Question 18 Question 19 To merge the standard error into the standard output 1 > &2 2 > &1 1& > 2 2 & > 1 Answer to Question 19 Question 20 To compile demo.c and run, we can use cc demo.c ; a.out cc demo.c ; demo.exe cc -c demo.c ; a.out Both A and B Answer to Question 20 Answers Answer 1 - A Back to question 1 Answer 2 - A Back to question 2 Answer 3 - D Back to question 3 Answer 4 - B Back to question 4 Answer 5 - B Back to question 5 Answer 6 - C Back to question 6 Answer 7 - B Back to question 7 Answer 8 - B

Back to question 8 Answer 9 - D Back to question 9 Answer 10 - C Back to question 10 Answer 11 - C Back to question 11 Answer 12 - B Back to question 12 Answer 13 - B Back to question 13 Answer 14 - A Back to question 14 Answer 15 - D Back to question 15 Answer 16 - D Back to question 16 Answer 17 - C Back to question 17 Answer 18 - A Back to question 18 Answer 19 - B Back to question 19 Answer 20 - A Back to question 20 corrections or comments. Question1 To get the PID of last background process echo $# echo $! echo $0

echo $$ Answer to Question 1 Question 2 The -v option of sh causes the shell to Debugs if shell script has any error Does nothing Echo each command before it is executed Gives verbal output Answer to Question 2 Question 3 The option to o test for zero length string is -s -z -a -d Answer to Question 3 Question 4 A file is identified by _____ associated with it Inode number Process-id number Group-id number User-id number Answer to Question 4 Question 5 The default value of umask is 777 644 022 422 Answer to Question 5 Question 6 Which of the following command is used to find the largest capacity of a file (m aximum bytes a file can hold) Umask Ulimit FLargeLimit None of the above Answer to Question 6 Question 7 Using ___ you can accept input from the standard input, process it and send the output to the standard output Filters Pipe

Both A and B None of the above Answer to Question 7 Question 8 What is the internal value associated with the standard error device? 0 1 2 None of the above Answer to Question 8 Question 9 Block commands work On group of lines On single line On a single file None of the above Answer to Question 9 Question 10 In which of the following modes vi (editor) works Command mode Insert mode Ex command mode All of the above Answer to Question 10 Question 11 Which commands help in viewing lines at the beginning or at the end of the file? Touch and cat Head and tail Touch and head Cat and tail Answer to Question 11 Question 12 Which of the following commands are used to save disk space? Ulimit Compress Pack Both B and C Answer to Question 12 Question 13 What is the command for viewing a compressed file? cat touch

zcat acat Answer to Question 13 Question 14 Password created for a user is stored in a file /dev/passwd /usr/passwd /etc/passwd /bin/passwd Answer to Question 14 Question 15 Which of the following is true? A DOS formatted floppy can be used in Unix and a Unix formatted floppy can be us ed in DOS A DOS formatted floppy can be used in Unix but a Unix formatted floppy cannot be used in DOS A Unix formatted floppy can be used in DOS but a DOS formatted floppy cannot be used in Unix None of the above Answer to Question 15 Question 16 Which of the following is a metacharacter? m> && $1..$9 All of the above Answer to Question 16 Question 17 Block command works in Command mode Insert mode Ex command mode All of the above Answer to Question 17 Question 18 How can you create hidden files in Unix *filename .filename $filename #filename Answer to Question 18 Question 19 What happens when the following command is executed?

(date; banner welcome; ls)> one 2>two date along with the banner and list of all the files is written into files one a nd two date along with the banner and list of all the files is written only into file t wo date along with the banner and list of all the files is written only into file o ne syntax error Answer to Question 19 Question 20 Which of the following command is used to execute commands at specified date and time? nohup cron fgrep None of the above Answer to Question 20 Answers Answer 1 - B Back to question 1 Answer 2 - C Back to question 2 Answer 3 - B Back to question 3 Answer 4 - A Back to question 4 Answer 5 - C Back to question 5 Answer 6 - B Back to question 6 Answer 7 - A Back to question 7 Answer 8 - C Back to question 8 Answer 9 - A Back to question 9

Answer 10 - D Back to question 10 Answer 11 - B Back to question 11 Answer 12 - D Back to question 12 Answer 13 - C Back to question 13 Answer 14 - C Back to question 14 Answer 15 - B Back to question 15 Answer 16 - D Back to question 16 Answer 17 - C Back to question 17 Answer 18 - B Back to question 18 Answer 19 - C Back to question 19 Answer 20 - B Back to question 20 Which of the following is true? Both user and superuser can execute the executable file etc/cron Only user can execute the executable file etc/cron Only superuser can execute the executable file etc/cron Neither the user nor the superuser can execute the executable file etc/cron Answer to Question 1 Question 2 What is the output of the following command? ls grep '^d' wc -l Gives a count of all the files starting with the word d gives a count of all the files except the files starting with the word d gives a count of all the files in present directory syntax error

Answer to Question 2 Question 3 What is the output of the following code A=$1 B=$2 for i in $A do mv $i ${i}$B done if the arguments passed are test *5t test* test*5t testtest*5t syntax error Answer to Question 3 Question 4 Default status permission for a file is set based on chmod Owner umask Group Answer to Question 4 Question 5 For setting environment variables in Unix which of the following files do you ed it .profile .exrc .login None of the above Answer to Question 5 Question 6 To compile program in Unix having mathematical library functions, we need to include math.h include stdlib.h cc filename -lm Both A and C Answer to Question 6 Question 7 What happens if the following command is executed? At 12:00 am Jan 1 Echo "happy New Year"

Syntax error At 12:00 am on January 1, displays the message happy new year on the terminal At 12:00 am on January 1, the following message is mailed by cron Incorrect usage of at command Answer to Question 7 Question 8 To list the files in a directory, we need to have Write permission to the directory Read permission to the directory Execute permission to the directory Both A and B Answer to Question 8 Question 9 Which one among the following is a filter command? ls awk vi None of the above Answer to Question 9 Question 10 What happens if you don't redirect the output to the terminal, when using at com mand It would throw a syntax error It would be mailed to us by the cron It would throw an error stating improper usage of the at command Nothing, because by default it would be redirected to the terminal Answer to Question 10 Question 11 Which of the following provides information regarding which users are allowed an d which users are disallowed from using the at command at.deny and at.allow at.allow and at.disallow at.deny and at.show All of the above Answer to Question 11 Question 12 Which command would you use to find out how much time is required to execute a p articular process? time nice who ps Answer to Question 12 Question 13

Using the kill command which of the following processes cannot be killed? sched vhand nice Both A and B Answer to Question 13 Question 14 The correct way to search for a pattern in a file one, sort that file and file c alled two and write the contents of the sorted files to a new file called three is grep test one sort - two > three grep test one sort cat two > three grep test one sort one sort two > three All of the above Answer to Question 14 Question 15 How can you say that a particular command is a filter or not? If the command takes only input from the standard input If the command send only output to the standard output If the command takes input form the standard input and it sends its output to th e standard output All of the above Answer to Question 15 Question 16 Which of the following files do you edit for setting the path in Unix .exrc .profile .login None of the above Answer to Question 16 Question 17 Which of the following shell variable would change the existing prompt to your n ame? PS1 PS2 PATH HOME Answer to Question 17 Question 18 What is the output of the following program? echo "Enter your name" read name t=`expr $name wc -c bc`

echo "The length of the given string is $t" if the input given is "this is a test from genesis" 5 28 22 Syntax error Answer to Question 18 Question 19 How to compile a list a files given as command-line arguments, and if they are c omplied successfully how do we run them? cc $* a.out cc $* && a.out cc $* -a a.out cc $* -o a.out Answer to Question 19 Question 20 If the grep command is successful in finding a pattern, it returns a exit status of 0 1 2 3 Answer to Question 20 Answers Answer 1 - D Back to question 1 Answer 2 - A Back to question 2 Answer 3 - B Back to question 3 Answer 4 - C Back to question 4 Answer 5 - B Back to question 5 Answer 6 - D Back to question 6 Answer 7 - C

Back to question 7 Answer 8 - C Back to question 8 Answer 9 - B Back to question 9 Answer 10 - B Back to question 10 Answer 11 - A Back to question 11 Answer 12 - A Back to question 12 Answer 13 - D Back to question 13 Answer 14 - A Back to question 14 Answer 15 - C Back to question 15 Answer 16 - B Back to question 16 Answer 17 - A Back to question 17 Answer 18 - D Back to question 18 Answer 19 - B Back to question 19 Answer 20 - A Back to question 20 Question1 How will you separate one command from another if you want to put several comman ds on the same line? :

-a ; Answer to Question 1 Question 2 If the following echo command is used, what would be the output Echo This is a test of * meta character in Unix operating system This is a test for * meta character in Unix operating system The meta character * is replaced by a list of all your files Improper usage of meta character in echo command Syntax error Answer to Question 2 Question 3 Contents of file "test" are as follows Echo ${1? "This is a test for argument"} is the only argument What is the output, if you execute the following file Bad substitution This is a test for argument Test is the only argument This is a test for argument is the only argument Answer to Question 3 Question 4 Which of following shell variables provides information of the command being exe cuted and its PID? $! and $0 and $$ and $$ and Answer $0 $$ $! $to Question 4

Question 5 What is the output of the following command if file one is undefined? sort one > one.sort 1>&2 two throws an error on the standard output and writes to file called two, stating fi le or directory does not exist throws an error only on the standard output, stating file or directory does not exist the standard error is redirected to the file called two, stating file or directo ry does not exist None of the above Answer to Question 5 Question 6 What is the output of the following command assuming the variable called name is defined as

Name=Genesis : ${name?' is the name of our organization'} Syntax error Genesis is the name of our organization Nothing, because it is a do nothing command Wrong usage of : , $ and ? in one statement Answer to Question 6 Question 7 Which of the following shell command is used as a comment in Unix // : # Both A and B Answer to Question 7 Question 8 To find the files containing word "printf" in the system find / find / find / find / Answer -name * -exec grep "printf" -name "*" -exec grep "printf" {} \; -name "*" -exec grep -l "printf" {} \; -name "*" -exec ls -l {} \; to Question 8

Question 9 What is the significance of fork function Kills an existing process Temporarily half an existing process Create a new process, killing the previous process Create a new process Answer to Question 9 Question 10 On successful completion of fork() It returns a value of 0 to the child process and also returns process ID of the child process to the parent process It returns a value of -1 to the parent process, with no creation of child proces s It returns a value of 0 to the parent process and also returns process ID of the child process to the parent process It returns a value of -1 to the child process and also returns process ID of the child process to the parent process Answer to Question 10 Question 11 What is the output of the following code main() { printf("Line1 ");

fork(); printf("Line2 "); } Line1 Line2 Line1 Line2 Line2 Line1 Line2 Line1 Answer to Question 11 Question 12 What is the output of the following code main() { printf("Line1 "); execl("/bin/date","date",0); printf("Line2 "); } Line1 followed by date Line1, date followed by Line2 Line1 followed by Line2 Syntax error Answer to Question 12 Question 13 The /etc/passwd file can be updated only by superusers. But a ordinary user can update his password through /bin/passwd executable file, because The owner can change his password Temporary permission is given to update /etc/passwd Superuser gives permission to change his passwd None of the above Answer to Question 13 Question 14 Which command waits until all background processes known to the current shell ha ve been terminated? sleep stop wait continue Answer to Question 14 Question 15 What does wait() system call return to all parent process, when a child process is created by fork()? PID of the child process Exit status of the child process Returns zero or one Both A and B Answer to Question 15

Question 16 Which command compares two text files? diff compare write tell Answer to Question 16 fQuestion 17 What is the output of the following statement? echo */* displays all files in all directories displays only the files in the current directory displays only the directories syntax error Answer to Question 17 Question 18 If you want to display message at the time of login, which of the following file s do you edit? /etc/passwd /etc/motd /etc/news /etc/msg Answer to Question 18 Question 19 Which of the following category of user can send message at the time of login? Only the superuser Only the users Only the groups Others Answer to Question 19 Question 20 What is the output of the following shell script? t=`cat /etc/passwd grep -s $1` echo $t if [ $? -eq 1 ] then Echo " $1 is not created" else Echo " $1 is created" fi Syntax error Improper usage /etc/passwd, is denied) Searches for the name given s displays the message name Searches for the name given because you cannot edit /etc/passwd (read permission at the command line in the /etc/passwd and on succes is not created at the command line in the /etc/passwd and on succes

s displays the message name is created Answer to Question 20 Answers Answer 1 - D Back to question 1 Answer 2 - B Back to question 2 Answer 3 - B Back to question 3 Answer 4 - B Back to question 4 Answer 5 - A Back to question 5 Answer 6 - C Back to question 6 Answer 7 - A Back to question 7 Answer 8 - C Back to question 8 Answer 9 - D Back to question 9 Answer 10 - A Back to question 10 Answer 11 - B Back to question 11 Answer 12 - A Back to question 12 Answer 13 - B Back to question 13 Answer 14 - C Back to question 14

Answer 15 - D Back to question 15 Answer 16 - A Back to question 16 Answer 17 - A Back to question 17 Answer 18 - B Back to question 18 Answer 19 - A Back to question 19 Answer 20 - D Back to question 20 What is the output of the program? echo "Give input \c";read str set $str echo " Give the word \c";read word count=0 for i in $* do if [ $i -eq $word ] then count=`expr $count + 1` fi done echo $count if the input is "This is a test to test your knowledge" and the given word to search is "test" Syntax error 8 2 9 Answer to Question 1 Question 2 Which of the following provides information about the current users and their te rminal types? who tr -s ' ' cut -f1,2 -d ' ' who tr -s ' ' cut -f1-2 -d ' ' who cut -f1-2 -d ' ' who cut -f1,2 -d ' ' Answer to Question 2 Question 3

How can you find out the exit status of a shell script using exit? echo $# echo $@ echo $? echo $?? Answer to Question 3 Question 4 What is the output of the following shell script, if a file "test" exists? cat test tr -sc A-Za-z sort uniq -c sort -n tail displays displays displays displays the last ten lines from the file "test" the first ten lines from the file "test" only the last line from the file "test" only the first line from the file "test"

Answer to Question 4 Question 5 What is the output of the following shell script? While true Do Sleep 5 Echo "\007 Check it out again \007" Done After every 5 seconds it displays the message \007 Check it out again \007 After every 5 seconds it displays the message Check it out again in bold letters After every 5 seconds it displays the message Check it out again with a beep sou nd None of the above Answer to Question 5 Question 6 Which of the following option is used to find out whether a given name is the na me of a file or a directory? -fd -d -ff -f Answer to Question 6 Question 7 Which command displays maximum of 10 lines from the end of the file? Head

Tail Both A and B None of the above Answer to Question 7 Question 8 Which of the following gives the count of number of links of a particular file? ls -l grep filename cut -f2 -d ' ' ls grep filename tr -s ' ' cut -f2 -d ' ' ls grep filename cut -f2 -d ' ' ls -l grep filename tr -s ' ' cut -f2 -d ' ' Answer to Question 8 Question 9 What is the signal number to terminate a process? 1 9 3 12 Answer to Question 9 Question 10 Console is a Ordinary file Character based file Stream None of the above Answer to Question 10 Question 11 When you login to Unix system kernel starts Init Getty Device files Both A and B Answer to Question 11 Question 12 What does the following statement perform? who -u grep unix tr -s ' ' cut -f6 -d ' '

It will search for It will search for It will search for lab None of the above Answer to Question Question 13

all the user logged, and return their login time all the user logged, and return their ideal time all the user logged, and return the time spend by them in the 12

Which command displays the first few lines of a particular file? grep tail search head Answer to Question 13 Question 14 What is the significance of execl()? It kills the original process and start a new process It continues the original process by overlaying memory with a new set of instruc tions It does not kill the original process but creates a copy of the existing one and starts a new process None of the above Answer to Question 14 Question 15 What would be the output of the following shell script "Display", if the files o ne, two and three exist echo Displaying the contents of all the files cat "$*" It is executed as: sh Display one two three displays the contents of the file one, two and three displays the contents of the file one and two displays the contents of the file two and three displays the message cannot open file one two and three Answer to Question 15 Question 16 // Old ones follow What does the following shell script do? echo "Enter the name ";read name for name do if [ -d $name ] then echo "YES" elif [ -f $name ] then echo "NO" else echo "JUNK" fi done displays YES if the given name is the name of a directory displays NO if the given name is the name of a file displays JUNK if the given name is neither a file nor a directory All of the above

Answer to Question 16 fQuestion 17 Which of the following command compares two files, and displays bytes and line n umber if there are differences? diff cmp comm ed Answer to Question 17 Question 18 What is the exit status of the following, if file "one" is existing and the othe r "file" two in not existing? cmp one two 0 1 2 4 Answer to Question 18 Question 19 When unix is adapted to a new kind of computer, what needs to be done? Commands has to be changed Command interpreter (shell) has to be modified Kernel has to be modified None of the above Answer to Question 19 Question 20 The command which waits for user to login is? Init Getty Kernel Getttydef Answer to Question 20 Answers Answer 1 - B Back to question 1 Answer 2 - A Back to question 2 Answer 3 - C Back to question 3

Answer 4 - A Back to question 4 Answer 5 - C Back to question 5 Answer 6 - D Back to question 6 Answer 7 - B Back to question 7 Answer 8 - D Back to question 8 Answer 9 - B Back to question 9 Answer 10 - B Back to question 10 Answer 11 - D Back to question 11 Answer 12 - B Back to question 12 Answer 13 - D Back to question 13 Answer 14 - B Back to question 14 Answer 15 - D Back to question 15 Answer 16 - D Back to question 16 Answer 17 - B Back to question 17 Answer 18 - C Back to question 18

Answer 19 - C Back to question 19 Answer 20 - B Back to question 20