Test Linux
Test Linux
intro
1. What is UNIX?
a) an operating system
b) a text editor
c) programming language
d) software program View Answer
Answer: a Explanation: UNIX is an operating system developed in the early 1970’s at Bell Labs by Dennis
Ritchie, Ken Thompson, and others. It is a multiuser, multitasking and timesharing operating system. The power
of UNIX is derived from its commands and their multiple options.
2. In which language UNIX is
written?
a) JAVA
b) Python
c) C++
d) C
View Answer Answer: d Explanation: UNIX was originally written in Assembly language but Dennis Ritchie
and Ken Thompson wanted an operating system which could run on more than one type of hardware. So in 1973,
they rewrote the whole operating system in C language due to which one of the strongest features i.e. portability
was added to the operating system.
3. Which of the following is not a feature of
UNIX?
a) multitasking
b) multiuser
c) portability
d) easy to use
View Answer Answer: d Explanation: UNIX is a multitasking operating system i.e. a user can run multiple tasks
concurrently. Similarly, it is a multiuser system because it permits working with multiple users on a single
operating system. But a major disadvantage of UNIX lies in the fact that the richness provided by its commands
requires a special type of commitment to understand the subject. i.e. the user must be well aware of commands
he is using and the functions performed by them.
4. Which of the following is not a part of all the versions of
UNIX?
a) Kernel and Shell
b) Commands and utilities
c) Graphical user interface
d) System Calls
View Answer Answer: c Explanation: The kernel is the heart of the operating system while the shell is the utility
which processes our requests. While system calls are a handful of functions which are used to interact with the
kernel and make available the services provided by the operating system. A Graphical user interface (GUI) is
available in UNIX, but the traditional UNIX interface is the command line only.
5. Which of the following is not true about
UNIX?
a) Many people can use a UNIX based computer at the same time; hence UNIX is called as a multiuser system
b) A user can run multiple programs at the same time; hence UNIX is called a multitasking environment
c) UNIX was not written in ‘C’ language
d) Linux is also known as a version of UNIX
View Answer Answer: c Explanation: One of the most attractive features of UNIX is that it supports multi-user
and multitasking environment which makes it so popular among its users. There are many UNIX variants
available in the market. Solaris Unix, AIX, HP Unix, BSD are some of the examples. Linux is also a flavor of
UNIX which is freely available. Unix was developed in 1969 by AT&T employees Ken Thompson, Dennis
Ritchie, Douglas McIlroy, and Joe Ossanna at Bell Labs and was written in ‘C’.
6. POSIX is a set of standards specified for establishing compatibility between
operating systems.
a) True
b) False
View Answer Answer: a Explanation: POSIX- Portable Operating System Interface for Computer
Environment is basically a set of standards specified by IEEE for establishing compatibility between operating
systems, especially which are UNIX based. For example, if we write a program relying on POSIX standards,
we can easily port it among a large family of Unix derivatives (including Linux).
7. Which part of the UNIX operating system interacts with the
hardware?
a) Kernel
b) Shell
c) vi editor
d) application program
View Answer Answer: a Explanation: The kernel is the core of the operating system. It is a collection of
routines written in C which directly communicates with the hardware. User programs that need to interact with
the hardware access the services of the kernel. There is only one kernel running on a system, unlike shells
which can be multiple.
8. What is a superuser?
a) system manager
b) normal user
c) administrator
d) a user with special rights
View Answer Answer: a Explanation: A superuser (root) is the UNIX system manager which can perform
special tasks like killing any executing program, resetting other users passwords, change users permissions and
performing other system management tasks. The administrator can switch to superuser by issuing su command
9. What is the windowing system of UNIX known
as?
a) X Window system
b) LINUX
c) Red Hat
d) DOS
View Answer Answer: a Explanation: The X window system, commonly known as X, is a windowing system
developed at MIT. It is an open-source, network transparent, client-server based system that provides a Graphical
user interface. X is primarily used on UNIX variants but it is also available for other operating systems also.
UNIX/LINUX COMMANDS - basics
10. 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
View Answer Answer: a 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.
11. In how many categories, commands of UNIX operating system
classified?
a) 1
b) 2
c) Many
d) 0
View Answer Answer: b 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.
12. Which command is used for extracting the details of the operating
system?
a) cd
b) echo
c) uname
d) wc
View Answer Answer: c 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.
13. The sequences of directories that a shell searches while looking for a command is specified in the
PATH variable.
a) True
b) False
View Answer Answer: a 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.
14. Options are also arguments but begin with
a -.
a) True
b) False
View Answer Answer: 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.
FILE
MANAGEMENT
32. A file is a container for storing
information.
a) True
b) False
View Answer Answer: a Explanation: We can define a file as a stream of characters or a container for
storing information. While working in a UNIX environment, we came across three categories of files
which are classified as- ordinary file, directory file and device file.
33. In how many broad categories, files are divided into
UNIX?
a) 2
b) 4
c) 5
d) 3
View Answer Answer: d Explanation: Files are divided into three major categories i.e. ordinary file, directory
file and device file. The characteristics of these three categories of files differ from each other and each category
has a predefined use.
34. In UNIX, the file name and file size are stored in the file
itself.
a) True
b) False
View Answer Answer: b Explanation: A UNIX file’s size is not stored in the file, nor its name. All this
information is stored separately in a separate area of hard disk which is not directly accessible to humans, but
only to the kernel. 35. 7. Device files are used by the kernel for operating the device.
a) True
b) False
View Answer Answer: a Explanation: Device files are nothing but special files which does not contain a stream
of characters but some attributes related to the devices which govern the operation of a device. The kernel reads
this file for the attributes to perform operations on any device.
36. When we log in, the UNIX places us in a directory, called ______
directory
a) home
b) main
c) parent
d) current
View Answer Answer: a Explanation: When we log in, the system automatically places us in a directory called
Home directory. We can change our directory if we want and can also view our home directory using the shell
variable, HOME.
37. UNIX treats everything as a file.
a) True
b) False
View Answer Answer: a Explanation: All physical devices such as printers, hard disk are treated as files by
the UNIX system. Even the kernel, shell and main memory is treated as a file by UNIX operating system.
38. The root directory is represented by ___
a) \
b) /
c) *
d) $
View Answer Answer: b Explanation: The root directory (/) serves as a reference point for all the files. All the
files are hierarchically below it. All files in UNIX are related to one another. The file system in UNIX is a
collection of all these related files (ordinary, directory and device files) organized in a hierarchical manner.
39. UNIX imposes no rule for framing filename extensions.
a) True
b) False
View Answer Answer: a Explanation: UNIX imposes no rules for framing filename extensions. For
example, a shell script doesn’t need to have the .sh implication, even though it helps in identification. In all
cases, it’s the application that imposes the restriction. For example, C compiler expects C program filenames
to end with .c .
40. _____ and _____ cannot be used in a filename.
a) /, NULL
b) $,^
c) ., %
d) NULL, $
View Answer Answer: a Explanation: UNIX imposes no rules in framing filename extensions but there are
some special characters which cannot be used while naming a file. / and NULL are the characters which cannot
be used in a filename.
41. We should avoid filenames starting with a –
(hyphen).
a) True
b) False
View Answer Answer: a Explanation: Those files which have filename starting with a (-) are difficult to
remove and many commands can interpret such filename as an option which could lead to a miserable
situation.
42. Which command is used for printing the current working
directory?
a) HOME
b) cd
c) pwd
d) dir
View Answer Answer: c Explanation: pwd command is used for checking our current directory. Current
directory is the directory in which we are currently working. pwd displays the absolute pathname i.e. with
respect to the root directory. $ pwd /home/stud5005/Stan&Bran
43. Which command is used for changing the current directory?
a) cd
b) cp
c) pwd
d) rm
View Answer Answer: a Explanation: cd (change directory) command is used for moving around the file system.
cd command is usually invoked with a argument. After invocation, it changes the current directory to the directory
specified as argument. Cp command is used for copying files while rm command is used for deleting files. For
example: our current directory is /bin/user06 and we want to change our directory to a directory named dir_one
which is inside the user06 directory. To do so, type the following: $ cd dir_one $pwd /bin/user06/dir_one
44. Which command is used for creating directories?
a) rmdir
b) mkdir
c) cd
d) cp
View Answer Answer: b Explanation: Directories in UNIX are created using mkdir command. The name of
the directory to be created is specified as an argument to the mkdir command. For example, to create a dir
named dir_01 in the current directory we can use the following command, $ mkdir dir_01
45. What does the following command do? $ mkdir dir dir/dir_01/dir_02
a) create dir, dir_01 and dir_02
b) creates dir_02
c) creates dir only
d) throws an error
View Answer Answer: a Explanation: The above command first creates a directory named dir and after that it
creates a subdirectory dir_01 under dir. At last, it creates another subdirectory dir_02 under dir_01. Thus a
directory tree is formed in which directory dir is the parent directory and dir_01, dir_02 are subdirectories.
46. Sometimes we are unable to create a directory because ______________
a) the directory may already exist in the current directory
b) there may be an ordinary file by the same name in the current directory c) the permissions set for the current
directory does not allow the creation
d) the directory may exist, there may be an ordinary file, the permissions set for the current directory does not
allow the creation View Answer Answer: d Explanation: Sometimes we are not able to create directory because
of multiple reasons as stated above.
47. Which command is used for removing an empty
directory?
a) mkdir
b) rmdir
c) del
d) remove
View Answer Answer: b Explanation: rmdir command is used for removing directories provided the directory
should be empty. For example, to remove a directory named dir_001 in the current directory type the following
command on the terminal. $ rmdir dir_001
48. If rmdir dir001 fails, what could be the
reason(s)?
a) dir001 doesn’t exist
b) dir001 is not empty
c) permissions of dir001 doesn’t allow to remove it
d) dir001 doesn’t exist, dir001 is not empty and permissions of dir001 doesn’t allow to remove it
View Answer Answer: d Explanation: There could be multiple reasons which could lead to failure while
removing a directory. Major reasons could be: -> directory doesn’t exists. -> directory is not empty. ->
permissions of directory doesn’t allow to remove it.
49. pwd and echo $HOME will display the same output.
a) True
b) False
View Answer Answer: b Explanation: pwd is used for displaying the absolute pathname of our current
working dircectory while $HOME displays the absolute pathname of our home directory. $ echo $HOME
/home/user08 // displays home directory $ pwd /home/user08/documents/template // displays current
directory
50. What is an absolute pathname?
a) pathname relative to a parent directory
b) pathname relative to the root (/)
c) pathname relative to parent and current directory
d) pathname relative to the current directory
View Answer Answer: b Explanation: When a file’s pathname is determined with respect to the root(/), such a
pathname is called absolute pathname. No two files in a UNIX system can have same absolute pathnames. Two
files can be of same name but in different directories hence their pathname would be different from each other.
For example, /bin/user06/dir_01 is an example of absolute pathname.
51. Which of the following cryptic symbols are used in relative
pathname?
a) ( . )
b) ( . . )
c) $
d) ( . ) and ( . . )
View Answer Answer: d Explanation: Relative pathname uses two
cryptic symbols which are ( . ) and ( . . ) (.) a single dot represent the
current directory. ( . . ) two dots represent the parent directory.
52. $ cp file_01 . copies the file named file_01 in ____
directory
a) current
b) parent
c) root
d) user
View Answer Answer: a Explanation: The ( . ) represents the current directory so the above command will
create a copy of file_01 in the current working directory.
53. The output of $HOME is an example of absolute
pathname.
a) True
b) False
View Answer Answer: a Explanation: HOME is a shell variable which prints our home directory. The
pathname specified by the output of HOME is an example of absolute pathname. $ HOME
/home/users/user_06
54. The output of the
following command
is __________ $ cp
abd/ .user_06
a) copies .user_06 file in current directory
b) copies .user_06 file in parent directory of directory named abd
c) undefined behavior
d) erroneous output
View Answer Answer: a Explanation: ( . ) single dot represents the current directory so the above command will
copy the file in the current directory. (.) is a cryptic symbol which represents current working directory and is
used in absolute pathname.
55. Which command is used for listing files in a directory?
a) ps
b) list
c) ls
d) wc
View Answer Answer: c Explanation: ls command is one of the most powerful commands used in UNIX system.
It comes available with a bunch of options for listing files available in the directory. There are a number of
options like -l, -a which are used for listing files in different manners according to user’s need. $ ls 001.sh FILE2
abc.txt dir08
56. 2. Which option is used with ls command for long listing of files with seven attributes?
a) -a
b) -l
c) -x
d) -i
View Answer Answer: b Explanation: -l is used with ls command for long listing of files in ASCII
collating sequence. The attributes displayed are: -> File type and permissions -> Links -> Ownership -
> Group ownership -> File size -> Last modification time -> Filename $ ls -l drwxr-xr-x 5 abd users
4096 Aug 12 08:30 go drwx------ 3 mash users 4096 Nov 28 10:49 irc drwxr-xr-x 2 ryan users 32768
July 25 09:15 logs drwxr-xr-x 8 anki users 4096 Oct 2 17:13 src
Answer: a Explanation: Like other UNIX commands, chmod can also descend a directory hierarchy and
apply the expression to every file and subdirectories it finds. This is done using -R option. For example,
chmod -R a+w dir01 This command will make all files and subdirectories found in the tree walk
executable by all users.
127. 11. UNIX allows the system administrator to use the only chown to change both owner
and group.
a) True
b) False
View Answer Answer: a Explanation: UNIX provides a special privilege for the system administrator to
change both the owner and group using chown command only. The syntax requires two arguments to be
separated by a (:). For example, chown abd:grp01 file01.txt // ownership to abd, group to grp01
128. 12. Which symbol is used to change permissions for hidden files
a) .
b) &
c) $
d) *
View Answer Answer: a Explanation: To change permissions for hidden files, use
the (.) symbol with chmod command.
VIM
EDITOR
129. 2. What does the following command do? $ vi file001
a) open file named file001
b) edit file named file001
c) delete a file named file001
d) open file if it exists else creates a new file
View Answer Answer: d Explanation: vi editor can be used for creating and editing files. In the above
command, if file001 already exists, then the contents of the file will be displayed. Otherwise, an empty file
named file001 will be created.
130. 5. What is the default mode of vi
editor?
a) Command mode
b) Input mode
c) Ex mode
d) Insert mode
View Answer Answer: a Explanation: The default mode of vi editor is command mode, where every key which
is pressed is interpreted as a command to run on the text. To perform operations on text like deleting, copying,
the first step you’ll have to follow is to be in the command mode so that you can run commands according to your
suitability.
131. 8. Which one of the following key is used to switch from command mode to input mode?
a) i
b) :
c) esc
d) ;
View Answer Answer: a Explanation: To switch from command mode to input mode press the ‘i’ key.
132. 10. Which of the following key is used to enter in
ex-mode?
a) ESC
b) i
c) :
d) ;
View Answer Answer: c Explanation: To enter into ex-mode press the ‘:’ key. After that, we can press any ex-
mode command followed by [Enter] to perform suitable operations.
133. ex-mode is used to save our
work.
a) True
b) False
View Answer Answer: a Explanation: One of the major functions performed in ex-mode is, saving our
work. For example, to save our file invoke the following command : :w [Enter] "file001", 10 lines, 456
characters
134. 5. While entering text in input mode the data is saved
in _____
a) buffer
b) disk
c) RAM
d) cache
View Answer Answer: a Explanation: If the file has not been saved yet then whatever we are inputting in it is
stored in a temporary storage called buffer. To save the data entered in the buffer, we have to switch to ex-mode.
135. 6. To quit vi editor without saving the buffer we
can use
a) :q
b) :c
c) :w
d) :q!
View Answer Answer: d Explanation: For quitting vi editor, there are numerous ways available in ex-mode as
well as in command mode. One way of which is to type ‘:q!’ in ex-mode.
136. 8. One of the most important features of vi editor is
_______
a) available mostly across all UNIX platforms
b) easy to learn
c) latest editor
d) powerful than other editors
View Answer Answer: a Explanation: vi is a versatile editor which is
now standard on all UNIX systems.
137. Input mode is used for
____________
a) editing text in files
b) invoking commands on files
c) saving files
d) performing substitution
View Answer Answer: a Explanation: To enter text in a file, we have to first switch to input mode. To enter into
input mode, press ‘i’ once. Any key pressed after that will appear on the screen as text input.
138. 2. Pressing ‘:’ in command mode invokes which mode of
vi editor?
a) ex-mode
b) insert mode
c) command mode
d) input mode
View Answer Answer: a Explanation: To invoke ex-mode we’ve to press the ‘:’ key in command mode. After
pressing : , we are in ex-mode. Now simply type any command of ex-mode to perform a suitable function.
139. 8. Which of the following command is a substitute for ‘:x’
command?
a) ‘:x’
b) :wq
c) :q
d) :w
View Answer Answer: b Explanation: We can also use the ‘:wq’ command to save and quit editor but it
requires an additional keystroke and it is not recommended for use.
140. Which of the following symbols are used for searching a pattern
in vi?
a) /
b) ?
c) %
d) / and ?
View Answer Answer: d Explanation: vi is extremely strong in searching for a pattern. Searching can be
made both in forward and in reverse directions using / and ? respectively.
141. 11. Which of the following commands can be used to replace ‘professor’ with ‘director’ throughout the
whole file?
a) 1,$s/professor/director/g
b) %s/professor/director/g
c) 1,$s/professor/director
d) 1,$s/professor/director/g and %s/professor/director/g
View Answer Answer: d Explanation: We can replace 1,$ with %. It will work same as
1,$. ‘g’ flag is used for global replacement.
SHELL BASICS
142. 6. What is the default symbol for command prompt in Bourne
shell?
a) $
b) %
c) #
d) @
View Answer Answer: a Explanation: If we are using bourne shell on our system, then the
default prompt will be represented by $.
143. 7. What is the default symbol for command prompt in C
shell?
a) $
b) %
c) #
d) @
View Answer Answer: b Explanation: If we are using C shell on our system, then the
default prompt will be represented by %.
144. 10. Which command does not terminates unless we log out of the system?
a) history
b) shell
c) echo
d) login
View Answer Answer: b Explanation: When we log on to a UNIX system, we first see a prompt. This prompt
remains there until we key in something. Even when we think the system is idling, a UNIX command is always
running at the terminal. This command is known as the shell. The shell is with us all the time and doesn’t
terminates unless we log out.
145. Which of the following expression is a correct wildcard pattern if we want an expression in which
the last
character is not numeric?
a) *[!0]
b) *[0-9]
c) [0-9]
d) *[!0-9]
View Answer Answer: d Explanation: Wildcards are used for pattern matching. The command *[!0-9] will
match all expression containing any characters except that the last character entered is not numeric. Here ‘!’
is used for NOT. *[!0] // last characters should not be 0 in the expression *[0-9] // any expression where the
last character is a numeric [0-9] // expression should only contains digits *[!0-9] // the last character should
not be numeric in the expression
146. 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
View Answer Answer: d Explanation: Shell is the agency that sits between the user and the UNIX system. It is a
unique and multi-faceted program. It is also called command-interpreter because it interprets our command
entered. It is also a programming language. From another point of view, the shell also provides us with an
environment to work in.
147. Wildcards are special characters which are used to replace or represent one or more
characters.
a) True
b) False
View Answer Answer: a Explanation: A wildcard is a special character which can be used as a substitute for
any of a class of characters, which increases the flexibility and efficiency of searching and replacing. For
example, to remove all the files with a filename starting with ‘chap’ prefix, we can use the command rm chap*.
Here * is used as a wildcard for matching all filenames starting with ‘chap’.
148. 2. Which of the following is not a wild-
card?
a) *
b) ?
c) $
d) %
View Answer Answer: c Explanation: The ‘$’ sign represents the shell prompt while all the other
characters belong to a category of shell wildcards. ‘*’ // matches any number of characters ‘?’ // matches
a single character
155. Which of the following shell doesn’t support ! symbol for negating the character
class?
a) mash
b) bash
c) POSIX
d) C
View Answer Answer: d Explanation: The ! symbol cannot be used to negate a character class in a C shell. In
fact, C shell doesn’t provide any mechanism for doing so.
156. Providing a backslash (\) before the wild card to remove its special meaning is called
_____
a) escaping
b) quoting
c) listing
d) pattern matching
View Answer Answer: a Explanation: We know that shell uses some special characters to match filenames or
perform other search and replace operations. But if the filename itself contains those special characters, then it
could be a great nuisance. For dealing with such files we use escaping and quoting. Escaping means providing a
backslash (\) before the wild card so that its special meaning could be removed. For example, if we want to
remove a file named chap*, then using the command rm chap* will delete all the file beginning with a prefix
’chap’. In this situation, we can use the following command, $ rm chap\*
157. To remove the file named my document.txt (with an empty space between my and document) which
one of the
following commands will be used?
a) rm my\ document.txt
b) rm my document.txt
c) rm *
d) rm my_document.txt
View Answer Answer: a Explanation: Apart from metacharacters, there are other characters that are special like
the space character. The shell uses it to delimit command line arguments. So to remove the file my document.txt
we can use escaping. The backslash will make the shell to ignore the space. Hence file will be removed easily.
158. We can escape the \ itself using
escaping.
a) True
b) False
View Answer Answer: a Explanation: Sometimes we may need to interpret the \ itself literally. To do
so we need another \ before it. For example, $ echo \\ // displays \
159. The output of the following command is ______________ $ echo ‘The special character $ echo hello and |
ls chap*’
a) undefined output
b) erroneous
c) hello
d) The special character $ echo hello and | ls chap*
View Answer Answer: d Explanation: Quoting is another way to turn off the meaning of a meta-character. When
a command argument is enclosed in quotes (‘), the meanings of all enclosed special characters are turned off.
REDIRECTION AND
PIPES
161. How many files are used for representing different standard
streams?
a) 1
b) 2
c) 4
d) 3
View Answer Answer: d Explanation: The shell associates three files with the terminal –two for display and
one for the keyboard. These special files are actually streams of characters which many commands see as input
and output. Each stream is associated with a default device – which is terminal. These three files are:
• Standard Input
• Standard output
• Standard error
162. The command wc < sample.txt will count data from the file
sample.txt.
a) True
b) False
View Answer Answer: a Explanation: When wc is used without any arguments it will read the data from the
default source which is a keyboard. In the above command, redirection symbol < is present. The following steps
are performed: 1. On seeing the <, the shell opens the disk file, sample.txt for reading. 2. wc performs its execution
and displays the output.
163. Which of the following symbol(s) can be used to redirect the output to a file or another
program?
a) |
b) >
c) >>
d) |, > and >>
View Answer Answer: d Explanation: All commands displaying output on the terminal actually write to the
standard output file as a stream of characters and not directly to the terminal as such. The symbol > will replace
the default destination (terminal) with any file by using the > operator, followed by the filename while the symbol
>> is used to append to a file. | is used to give input to another program.
164. The >> symbol is used to overwrite the existing file
if it exists.
a) True
b) False
View Answer Answer: b Explanation: The shell provides the >> symbol (right chevron used twice)
to append to an existing file. For example, //Do a word count program on sample.txt and append the
output to newfile as shown below. $ wc sample.txt >> newfile
165. The category of commands which uses both standard input and standard output are
called ____
a) directory oriented commands
b) standard input commands
c) filters
d) standard output commands
View Answer Answer: c Explanation: UNIX commands can be
grouped into four categories: Directory-oriented (mkdir,rmdir)
Commands like ls, pwd that write to standard output Commands like
lp that read from standard input Filters – commands which use both
standard input and standard output (like bc)
166. The contents of decalculat.txt
are:
1000 20*25 What will be the contents of result.txt
when we would use: $ bc < decalculat.txt > result.txt
a) Undefined
b) Erroneous
c) 1000 500
d) 2
Answer: c Explanation: We can redirect bc’s
standard input to come from file001 and save the
output in another file named result.txt. bc obtained
the expressions from the redirected standard input,
processed them and sent out the results to a
redirected output stream. Here bc command is used
as a filter.
167. Which of the following files are known as special files
in UNIX?
a) sample.txt
b) /dev/null
c) /dev/tty
d) /dev/null and /dev/tty
View Answer Answer: d Explanation: There are two special files named /dev/null and /dev/tty which is used in
UNIX for special purposes. For example, if we want to check whether the program runs successfully without
seeing its output on the screen or may not want to save output in a file either. For this purpose, a special file
/dev/null is used. It accepts any stream without growing in size. The second file /dev/tty is the one used for
indicating one’s terminal.
168. Which symbol is used to redirect error messages to
/dev/null?
a) %
b) $
c) >
d) <
View Answer Answer: c Explanation: As we redirect our output using > symbol to other files in simple
commands, this technique can also be used to redirect error messages to /dev/null file. For example, $ cmp
file01 file02 > /dev/null
169. Which symbol is used to connect different
streams?
a) |
b) >
c) <
d) ~
View Answer Answer: a Explanation: The shell can connect different streams using a special operator called
pipe (|) and avoid creation of disk file. We can connect two commands using this operator so that one command
can take the output of other as its input. For example, $ who | wc -l // count number of lines in the output of who
command.
170. We can use the > symbol along with pipe in a
command.
a) True
b) False
View Answer Answer: a Explanation: There is no restriction on the number of commands we can use in a
pipeline except that we should know the behavioral properties of these commands to place there. For example,
consider this command: $ ls | wc -l > output.txt // number of lines counted by wc command from the output
of ls //are stored in a file named output.txt
171. Which command saves one copy of character stream in a file and store the other to standard
output?
a) who
b) ls
c) tee
d) wc
View Answer Answer: c Explanation: tee command handles a character stream by duplicating its input. It
saves one copy in a file and writes the other to standard output. For example, $ who | tee user.txt
Above command will the save the output of who command in a file named user.txt as well as it will also display
the output of who command on the terminal.
172. Apart from its use in redirection, /dev/tty can also be used as an argument to some
commands.
a) True
b) False
View Answer Answer: a Explanation: /dev/tty can be used as an argument to some UNIX commands. Because
the terminal is also a file we can use the device name /dev/tty as an argument to some commands like tee. For
example, $ who | tee /dev/tty | wc -l // same as who | wc -l In the above command, tee saved the output of who
in /dev/tty, thus effectively showing it on the screen and wc -l counted the number of lines from another
stream.
173. Shell enables one or more arguments to be obtained from the standard output of another command. This
feature
is called _________
a) command substitution
b) argument substitution
c) shell substitution
d) korn
View Answer Answer: a Explanation: Apart from a pipeline, shell enables connecting of two commands in
another way. Shell enables one or more arguments to be obtained from the standard output of another command.
This feature is called command substitution. For example, to display output like: Today’s date is Sat Jan 05
17:25:41 IST 2002 We can use the following command $ echo “Today’s date is `date`” // date is an argument to
echo command
174. Which of the following meta-character is used in command
substitution?
a) `
b) ‘
c) “
d) >
View Answer Answer: a Explanation: When scanning the command line, the shell looks for another
metacharacter i.e. ` (the backquote) usually placed on the top-left of our keyboard, and it should not be confused
with a single quote (‘).
175. POSIX recommends the use of ____ instead of archaic `command ` for command
substitution.
a) |
b) #
c) %
d) $
View Answer Answer: d Explanation: POSIX recommends the use of the form $(command) instead of archaic
` command` for command substitution. For example, to display the date using command substitution use the
following command: $ echo The date is $(date) Output: The date is Sat Jan 05 17:25:41 IST 2017