This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Commands”.
1. What are Commands?
a) specific instructions for performing a particular task
b) part of the operating system
c) part of the shell
d) special instructions
Explanation: Commands are basically specific instructions which are given by the users to perform a particular piece of a task. In UNIX, commands are entered by the user through a command line interface which further is processed by the command interpreter i.e. Shell.
2. In how many categories, commands of UNIX operating system classified?
Explanation: There are two broad categories in which the classification of commands is based on UNIX. They are namely—external commands and internal commands. External commands are those commands that have an independent existence in the /bin directory i.e. these are the executables which are present in separate files while Internal commands are built-in commands which are built into the shell. Example, ‘ls’ is an external command while ‘echo’ is an internal command.
3. Which command is used for extracting the details of the operating system?
Explanation: uname command is used for extracting the details like name, version of the operating system running on the machine. the cd command is used for changing directories and echo command is used for displaying the contents of a string on to the output stream. wc command is used for counting words and other details in a file.
4. The sequences of directories that a shell searches while looking for a command is specified in the PATH variable.
Explanation: When we specify a command, the shell searches for that command in the list of directories specified in the PATH variable and then executes it after locating the command successfully.
5. Options are also arguments but begin with a -.
Explanation: Arguments are parameters which are specified along with commands so that the command can perform an operation or take input from that parameter while options are also arguments but they are predetermined i.e. they perform a particular task. For example, echo hello. In this command hello is an argument while in ls – l, -l is an option.
6. Which of the following is not a valid option of uname?
Explanation: uname command is used for printing the information about the current system. -a is used for printing all the information including version name, kernel name, kernel release, machine hardware name etc. -s is used for printing only the kernel name while -v is used for printing the kernel version.
7. How can we specify more than one command in the command line at the same time?
a) using ;
b) using >
c) using ==
d) not possible
Explanation: UNIX allows us to specify more than one command at the same time in the command line. To do so, we have to separate each command from each other using (;). For example, wc file1 ; ls -l file1 . The > symbol allows us to redirects the output of the command(s). For example, wc file1 > file2. Now, file2 will contain the output produced by the wc file1 command. Both ; and > are called metacharacters.
8. Which command is used to display the documentation of commands in UNIX?
Explanation: UNIX provides us with a facility of man command, which is used for getting documentation of any command. For example, to seek help on wc command simply type man wc. This will simply display all the possible operations, options, description, synopsis of wc command. The POSIX specification requires only one available option with man command i.e. -k, which prints a one-line description of the command. whatis command is also available on many UNIX systems which also displays a one-line description of the command. man -f emulates the behavior of whatis command.
9. Which command is used for displaying date and calendar in UNIX?
a) date and cal
b) DATE and CAL
c) date and calendar
d) dt and cl
Explanation: date command is used for displaying the current system date and time while cal command is used to see the calendar of any specific month/year.
10. What is the output of who command?
a) display information about users who are currently logged in.
b) display file hierarchy
c) display administrator information
d) display processes
Explanation: who command output the details of the users who are currently logged in to the system. The output includes username, terminal name (on which they are logged in), date and time of their login etc.
11. What are meta-characters?
a) special characters having predefined meaning to the shell
b) special symbols
c) shell symbols
d) command symbols
Explanation: meta-characters are special characters having a predefined meaning to the shell. They are used as wild cards for special purposes like pattern matching, output redirecting etc. *, |, < are meta-characters.
12. Which command is used for displaying date in the format dd/mm/yyyy ?
a) date +%m
b) date +%h
c) date +”%d/%m/%Y”
d) date +”%h %m”
Explanation: Date command can use format specifiers as arguments with each specifiers preceding with a + , followed by % operator and a single character for describing the format.
$ date +%m -display current month $ date +%h -display the name of the month $ date +"%h %m" -display both month and month name
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.