You are on page 1of 12

This set of Unix Multiple Choice Questions & Answers focuses on �Shell Programming

using read Command and Command Line Arguments�.

1. What is a shell script?


a) group of commands
b) a file containing special symbols
c) a file containing a series of commands
d) group of functions

2. Shell scripts need to be saved with an extension .sh .


a) True
b) False

3. Shell scripts are executed in a separate child shell process.


a) True
b) False

4. The first line in any shell script begins with a _____


a) &
b) !
c) $
d) #

5. To run the script, we should make it executable first by using _____


a) chmod +x
b) chmod +r
c) chmod +w
d) chmod +rwx

6. To spawn a child of our own choice for running the script, we can use ___
command.
a) ps
b) pr
c) sh
d) $$

7. Which command is used for making the scripts interactive?


a) ip
b) input
c) read
d) write

8. read command is shell�s internal tool.


a) True
b) False

10. What are positional parameters?


a) special variables for assigning arguments from the command line
b) pattern matching parameters
c) special variables for reading user input
d) special variables and patterns
11. The first argument is read by the shell into the parameter ___
a) 1$
b) $3
c) $$
d) $1

12. The complete set of positional parameters is stored in ______ as a single


string.
a) $n
b) $#
c) $*
d) $$

13. Which of the following is used for storing the number of positional parameters?
a) $n
b) $#
c) $*
d) $2

14 Which of the following is not a feature of UNIX?


a) multitasking
b) multiuser
c) portability
d) easy to use

15 Shell is a command interpreter used for interacting with a UNIX system.


a) True
b) False

16. Which part of the UNIX operating system interacts with the hardware?
a) Kernel
b) Shell
c) vi editor
d) application program

17. history command displays the log of recently used commands.


a) True
b) False

18 history command displays the log of recently used commands.


a) True
b) False

19In how many broad categories, files are divided into UNIX?
a) 2
b) 4
c) 5
d) 3

20Each entry of directory file has component(s) namely _____


a) filename
b) inode number
c) filename and inode number
d) file size
21When we log in, the UNIX places us in a directory, called ______ directory
a) home
b) main
c) parent
d) current

22 The root directory is represented by ___


a) \
b) /
c) *
d) $

23 cd command cannot be used without any argument.


a) True
b) False

24 We can create multiple directories by single invocation of mkdir command.


a) True
b) Fals

25 Which option is used with ls to display attributes of the directory ?


a) -a
b) -ld
c) -d
d) -o

26 -a option is used with ls command for what purpose?


a) for showing hidden files
b) for showing executables
c) for showing directories
d) for multi columnar output

27 What does the -S option do in ls command?


a) sorts according to modification time
b) sorts according to last access time
c) sorts according to file size
d) sorts according to inode number

28 ls -t option sorts the files according to ____


a) last modification time
b) last access time
c) ASCII collating sequence
d) file size

29 The output of ls dir* is ___


a) all files in the current directory
b) all files in the directory having a filename starting with dir
c) no filename is displayed
d) erroneous

30 Apart from displaying file contents, cat command is also used for _____ files.
a) displaying
b) deleting
c) copying
d) creating

31 Which symbol is used with cat command for creating files?


a) >
b) <
c) *
d) /

32 Which symbol is used to append an existing file?


a) >
b) <
c) >>
d) $

33 Which option is used with the cat command for displaying file with line numbers?
a) -n
b) -v
c) -a
d) -x

34 Which of the following cannot be performed by cat command?


a) displaying files
b) creating files
c) appending files
d) deleting files

35 What does cat file01 file01 file01 display?


a) error
b) blank terminal
c) contents of file01 three times successively
d) contents of file01 single time

36 Which command is used to create empty files?


a) cp
b) cat
c) touch
d) create

37 Which one of the following commands is incorrect?


a) cat file01
b) cat > file01
c) cat >> file1
d) cat -a file01

37 We can delete multiple files using a single rm command.


a) True
b) False

38 To delete all files in a directory we use ______________


a) rmdir *
b) mv *
c) rm *
d) del *

39 Which option is used with rm command for interactive deletion?


a) -i
b) -f
c) -r
d) -R

40 Which option performs recursive deletion?


a) -r
b) -R
c) *
d) -r and -R

41 Which option is used for counting the number of lines in a file only with wc
command.
a) -l
b) -W
c) -c
d) -w

42 What does the following command do?

$ wc sample.txt > newfile


a) reads word count from sample.txt
b) reads word count from newfile
c) reads word count from sample.txt and write it to newfile
d) error is produced

43 Which command is used to change the permissions of a file?


a) chmod
b) ch
c) chown
d) chgrp

44 chmod command can be used in ____ ways.


a) 3
b) 2
c) 5
d) 0

45 Which of the following characters specify the user and group category?
a) �u� and �g�
b) �g� and �o�
c) �us� and �gr�
d) �u� and �o�

46 Which of the following symbol is used with chmod to assign permission to a file?
a) �
b) /
c) +
d) *

47 To assign execute permission to the user (owner) for a file named file01.txt,
which of the following command will be used?
a) chmod u+r file01.txt
b) chmod u+w file01.txt
c) chmod u-x file01.txt
d) chmod u+x file01.txt

48 What does the following command do?

$ chmod ugo +w file01.txt


a) assign write permission to users, group and others
b) assign write permission to the user (owner) only
c) assign write permission to group and others
d) command not executable
49 Which character is used to replace �ugo� string in chmod command?
a) a
b) v
c) x
d) o

50 To remove write permission from group and others, which one of the following
commands will be used?
a) chmod go+w file01
b) chmod go-w file01
c) chmod ug-w file01
d) chmod a-w file01

51 There can be multiple kernels on a single UNIX system.


a) True
b) False

52 Which one of the following command will display the name of the shell we are
working on?
a) echo shell
b) echo $
c) echo $SHELL
d) echo $$

53 Which of the following is/are true about Shell?


a) Shell is a multi-faceted program
b) Shell is a command interpreter
c) Shell provides us with an environment to work in
d) Shell is a multi-faceted, command interpreter and provides an environment to
work in

54 Redirection is a process of switching of the standard stream of data.


a) True
b) False

55 How many files are used for representing different standard streams?
a) 1
b) 2
c) 4
d) 3

56 Which stream is connected to the display?


a) standard input
b) standard output
c) standard error
d) error

57 The command wc < sample.txt will count data from the file sample.txt.
a) True
b) False

58 Which of the following symbol(s) can be used to redirect the output to a file or
another program?
a) |
b) >
c) >>
d) |, > and >>
59 The >> symbol is used to overwrite the existing file if it exists.
a) True
b) False

60 The UNIX shell is both _______ and _______ language.


a) interactive, responsive
b) interpreter, executing
c) scripting, interpreter
d) high level, low level

61 Which one of the following command is used to create a child shell?


a) fork
b) wait
c) sh
d) env

62 ____ command is used to display the environment variables only.


a) set
b) env
c) sh
d) var

63 Which one of the following is not an environment variable?


a) HOME
b) PATH
c) USER
d) env

64 ___ command is used for displaying the end of the file.


a) head
b) tail
c) lp
d) pr

65Which command is used for locating files?


a) search
b) find
c) loc
d) type

66 What will be the output of the following command?

$ find / -name a.out -print


a) all files having filename as a.out
b) all files in the root directory
c) undefined output
d) erroneous

67 Which option is used with find command for specifying the file type?
a) -perm
b) -inum
c) -name
d) -type

68 Which option is used to find command to search for files based on access time?
a) -atime
b) -mtime
c) -time
d) -type

69 Sort command uses ____ as default field delimiter.


a) tab
b) single space
c) double tab
d) one or more continuous spaces

70 Which option is used with sort command to specify the field delimiter?
a) -a
b) -t
c) -k
d) -n

71 The sort order can be reversed using ___ option.


a) -t
b) -k
c) -r
d) -n

72 Which option is used when we�ve to sort files containing only numbers?
a) -n
b) -a
c) -d
d) -u

73 . _____ option is used with sort command for removing repeated lines.
a) -n
b) -u
c) -t
d) -a

74 Which option is used by the sort command to redirect the output to a specified
file?
a) -n
b) -t
c) -o
d) -u

75 Which one of the following command is used for searching for a pattern in one or
more file(s)?
a) cd
b) cp
c) paste
d) grep

76 Which one of the following is the correct syntax for grep command?
a) grep options filename(s)
b) grep options pattern
c) grep pattern filename
d) grep options pattern filename(s)

77 Which one of the following command will be used for searching �director� in
emp.lst?
a) grep �director�
b) grep -v �director� emp.lst
c) grep -director emp.lst
d) grep �director� emp.lst
78 grep command can be used for searching a pattern in more than one file.
a) True
b) False

79 Which option is used with grep command for ignoring the case in pattern
searching?
a) -a
b) -v
c) -i
d) -e

80 Which option is used with grep command for deleting lines?


a) -v
b) -e
c) -a
d) -i

81 grep command supports both extended and regular expressions.


a) True
b) False

82 Character class is used for matching a group of characters enclosed within a


pair of _____
a) ( )
b) � �
c) [ ]
d) { }

83 Which of the following symbol is used for matching the immediately preceding
character?
a) *
b) $
c) [ ]
d) %

84 The following command will match the lines beginning with �2�.

$ grep �^2� emp.lst


a) True
b) False

85 What happens if the destination file specified in cp command does not exist?
a) file will not be copied
b) an error will be produced
c) destination file will be automatically created
d) none of the mentioned

86 Which of the following is not an option of cp command?


a) -z
b) -i
c) -R
d) -u

87 How can we copy an entire directory under another directory?


a) using -R option
b) using -a option
c) using -u option
d) none of the mentioned

88 What does -i option do in copy?


a) interactive copying
b) recursively copying
c) updating
d) none of the mentioned

89 Which command is used for comparing two files?


a) cmp
b) comp
c) diff
d) comm

90 What is the exit status of cmp command if both the files are identical?
a) 0
b) 1
c) 2
d) undefined

91 user gives a command to search for specific files as a background process and
edit a 'C'
program file using vi editor. This is an example of:
a. Multithreading
b. Multiprogramming
c. Time sharing
d. Multitasking

92 All commands that are reserved for the administrator is stored in:
a. /bin
b. /usr
c. /etc
d. /tmp

93 All the user commands are stored in the directory:


a. /etc
b. /usr
c. /tmp
d. /bin

94 . A user created a file using the command: cat>myfile The file created would be:
a. None of the above
b. Special file
c. Ordinary file
d. Directory file
95 The command to go back to home directory from any directory is :
a. Cd .
b. Cd..
c. Cd
d. Cd HOME

96 The directory given to a user soon after login is referred as:


a. Working Directory
b. Present directory
c. User directory
d. Home directory
97 The output of 'ls -l' command gives a line 'Total 160'. The value 160 refers to:
a. Total number of files
b. Total number of blocks
c. Total number of directories
d. Total number of inodes

98 A user wants to display long listing of all files and its subdirectories
including the hidden files
recursively from the current directory. The command is:
a. Ls -laR
b. Ls -a
c. Ls -lar
d. Ls -la

99 A file is created using 'cat>myfile'. Later the user again issued the command
'cat>myfile'. This
will result in:
a. Displaying an error since the file is already created
b. Overwriting the existing file 'myfile' with new content
c. Appending the new content to the existing file 'myfile'
d. Creating two files with one file automatically marked as 'copy of'

100 To delete a directory, which contains other subdirectories and files with user
confirmation,
the command is:
a. Rmdir
b. Rm -r
c. rm -ri
d. Rm -

101 . To delete all ordinary files which starts with a number from the current
directory, the
command is:
a. rm ?*
b. rmdir [0-9]*
c. rm #*
d. rm [0-9]*

102. Which command is used to find the users, who have currently log on?
a. WHO
b. Whoami
c. who
d. Who am i

103 To rename a file, the command in UNIX is:


a. Rname
b. md
c. Ren
d. mv
104 A user issues the command 'chmod 770 myshell1'. The File Access Permission
(FAP) for this file
will be:
a. -------rwx
b. Cannot be determined
c. -rwxrwx---
d. -rwxrwxrwx

105 A command that takes input from standard input file and gives output to
standard output file
is called:
a. Filter
b. Named pipes
c. Semaphore
d. Pipe

106 A feature of unix that allows output of a command is treated as an input to the
subsequent
command is :
a. Filter
b. Semaphore
c. Pipe
d. Background processing

107 Which of the following characters is used to represent ordinary files


for the first character of the File Access Permission list?
a. ?
b. *
c. |
d. -

108 Which option of cut filter display the column specified?


a. �d
b. �c
c. �f
d. -s

109 What is the true about the following command? grep �New[^a-c]�
a. pattern must contain any character in the set specified
b. Pattern following it must occur at the beginning of each line
c. Patern must not contain any character in the set specified.
d. pattern following it must not orrur at the beginning of each line

You might also like