Unix MCQ (Multiple Choice Questions)
Here are 1000 MCQs on Unix (Chapterwise).
1. What is Unix?
a) Unix is a programming language
b) Unix is a software program
c) Unix is an operating system
d) Unix is a text editor
View Answer
Answer: c
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. The Unix shell is both _______ and _______ language.
a) scripting, interpreter
b) high level, low level
c) interactive, responsive
d) interpreter, executing
View Answer
Answer: a
Explanation: The UNIX shell is both an interpreter and scripting
language. We can also say that shell can be interactive or non-
interactive. When we log in to our system, interactive shell presents a
prompt and wait for our requests while a non-interactive shell is
managed by an interactive shell while executing a shell script.
3. In which language UNIX is written?
a) C++
b) C
c) JAVA
d) Python
View Answer
Answer: b
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.
4. Which of the following is the first UNIX editor?
a) vi
b) emacs
c) ex
d) ed
View Answer
Answer: d
Explanation: The first editor that was used in UNIX systems was ‘ed’.
The main reason behind the replacement of ‘ed’ was that it can only
edit files in the current directory and cannot execute shell commands.
5. Which of the following is not a feature of Unix?
a) multiuser
b) easy to use
c) multitasking
d) portability
View Answer
Answer: b
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.
advertisement
6. Which of the following is not true about Unix?
a) UNIX was not written in ‘C’ language
b) Linux is also known as a version of UNIX
c) A user can run multiple programs at the same time; hence UNIX is
called a multitasking environment
d) Many people can use a UNIX based computer at the same time; hence
UNIX is called as a multiuser system
View Answer
Answer: a`
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’.
7. Which editor is used by the Unix system to edit files?
a) word
b) notepad++
c) vi
d) notepad
View Answer
Answer: c
Explanation: It doesn’t matter what kind of work we are doing on a
UNIX system, we always need an editor to edit some system files or
ordinary files. For this purpose, vi editor is used in UNIX. Currently,
vim (vi improved) is an improved version which is supported by
LINUX systems.
8. Which of the following is not a part of all the versions of Unix?
a) System Calls
b) Graphical user interface
c) Kernel and Shell
d) Commands and utilities
View Answer
Answer: b
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.
9. Which part of the Unix operating system interacts with the hardware?
a) Application program
b) Vi editor
c) Shell
d) Kernel
View Answer
Answer: d
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.
10. Which command is used to display the documentation of commands
in Unix?
a) man
b) whatis
c) help
d) search
View Answer
Answer: a
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.
11. Which Unix command is used for changing the current directory?
a) pwd
b) rm
c) cd
d) cp
View Answer
12. Which command is used for printing the current working directory?
a) dir
b) HOME
c) cd
d) pwd
View Answer
Answer: d
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/user06/Abdullah
13. Which command is used for listing files in a directory?
a) list
b) ls
c) wc
d) ps
View Answer
14. Which command is used by the user to change their login password in
Unix?
a) cp
b) man
c) reset
d) passwd
View Answer
Answer: d
Explanation: Since UNIX is a multiuser system, it requires a password
from every user who wants to log in to the system to help ensure that
all the data and files of the user are secure from hackers and errant
users. A user can simply change his/her login password by using the
passwd command. Simply type this command on the terminal and then
enter the old password, which after successful verification would allow
the user to input a new password for his login.
15. Which command is used for displaying the contents of a file in Unix?
a) mkdir
b) cat
c) rm
d) cp
View Answer
16. Which command is used to compress files?
a) gzip
b) gunzip
c) comm
d) cmp
View Answer
17. Which command is used for displaying the beginning of a file in Unix?
a) lp
b) begin
c) pr
d) head
View Answer
Answer: d
Explanation: The head command is used for displaying the top of the
file. As the name suggests, it displays the beginning of the file which is
specified as an argument to the command. For example,
$ head [Link]
18. Which symbol is used with the tail command to print the file from the
selected line?
a) %%
b) ^
c) +
d) –
View Answer
Answer: c
Explanation: We can also address lines from the beginning instead of
the end. The +count option allows us to do that, where count represents
the line number from where the selection should begin. For example,
$ tail +11 [Link] // start printing from 11th line onwards
19. Which command is used to delete all files in a directory?
a) del *
b) rm *
c) mv *
d) rmdir *
View Answer
Answer: b
Explanation: To delete all files in a directory, use (*) with rm command.
It acts as a meta-character and delete all files without displaying any
message on the terminal. So use this command cautiously.
20. echo command is used for _________
a) displaying diagnostic messages
b) displaying date and time
c) displaying errors
d) displaying operating system details
View Answer
Answer: a
Explanation: echo command is generally used for displaying diagnostic
messages on to the terminal or to issue prompt for reading the user
input. All shells now have echo built in i.e. it is an internal command.
$ echo hello
hello
21. What is the function of cp command in Unix?
a) delete a given file
b) change the directory
c) list all the available files in the current directory
d) cp is a command used for copying files and directories
View Answer
Answer: d
Explanation: cp command is basically used for creating a copy of
source file or a group of files. The syntax of the command requires at
least two filenames to be specified. If both the files specified are
ordinary files, the first file will be copied to the second file. The syntax
of cp command is cp source_filename destination_filename. The
contents of the source file will be copied to the destination file in the
same directory.
$ cp file_01 file_02 // copies file_01 to file_02
22. Which command is used for removing/deleting files in Unix?
a) rm
b) mv
c) rmdir
d) del
View Answer
Answer: a
Explanation: rm command is used in UNIX to remove one or more files.
It operates silently and should be used with caution. The filename of
the file to be deleted is provided as an argument to rm command. For
example, following command deletes [Link] file.
$ rm [Link]
23. Which command is used for renaming files in Unix?
a) rename
b) move
c) mv
d) cp
View Answer
Answer: c
Explanation: mv command is used for renaming files. This command
does not create a copy of the file, it simply renames it. To rename file1
to file2 simply type,
$ mv file1 file2
24. Which command is used for comparing two files?
a) comp
b) cmp
c) comm
d) diff
View Answer
Answer: b
Explanation: cmp command is used for comparing two files byte by
byte. It displays the first mismatch and its location on the terminal. It
does not bother about subsequent mismatches but displays only the first
mismatch. As soon as the first difference is found, the command
terminates and outputs the line and byte in which there is a difference.
For example,
$ cmp file01 file02
file01 file02 differ: Byte 20, Line 2
diff command is used for converting one file into another in order to
make them identical and comm is used for displaying the common
elements in both the files.
25. Which Unix command is used for counting words, lines, and
characters in a file?
a) wc
b) man
c) count
d) diff
View Answer
Answer: a
Explanation: UNIX provides a universal word counting program that
allows us to count the number of words, lines and characters in a file. It
takes a filename as an argument as produces a 4 column output.
$ wc file01
3 9 45 file01
Above output indicates that file01 contains 3 lines, 9 words and 45
characters.
26. In UNIX, which command is used to change the permissions of a file?
a) chown
b) chgrp
c) chmod
d) ch
View Answer
Answer: c
Explanation: The chmod (change mode) command is used to change
the permissions of files. This command can only be run by the owner of
the file or by the super user.
27. Which symbol is used to change permissions for hidden files in Unix?
a) *
b) $
c) &
d) .
View Answer
Answer: d
Explanation: To change permissions for hidden files, use the (.) symbol
with chmod command.
$ chmod 755 . // works on hidden files
28. Which command is used for saving and quitting the vi editor
simultaneously?
a) ‘:x’
b) :f
c) :q
d) :w
View Answer
Answer: a
Explanation: ‘:x’ command saves our content and quits the editor
simultaneously. This command is invoked in ex-mode.
29. How can we escape to the UNIX shell without quitting vi editor?
a) using ‘:sh’ command and using ctrl-Z
b) using ‘:sh’ command
c) using ctrl-Z
d) using ctrl-D
View Answer
Answer: a
Explanation: We can escape to the shell without quitting the editor
using ‘:sh’ command or ctrl-Z. Sometimes it is necessary to return to
shell prompt to execute a UNIX command or compile our program. For
this purpose, we use these commands.
30. For creating and removing directories, which of the following system
calls are used?
a) mkdir and rmdir
b) rmdir and chown
c) chdir and chown
d) mkdir and chdir
View Answer
Answer: d
Explanation: A non privileged user uses mkdir and rmdir calls for
creating and removing directories respectively.
31. Which of the following files are known as special files in Unix?
a) /dev/null
b) [Link]
c) /dev/null and /dev/tty
d) /dev/tty
View Answer
Answer: c
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.
32. What is the output of the following Unix command?
$ wc -c *.c
a) size of each .c file
b) total size of .c files
c) erroneous
d) undefined
View Answer
33. In Unix, for what purpose bc command is used?
a) for copying files
b) as a process table viewer
c) as an editor
d) as a calculator
View Answer
34. Which process is immediately set up by the kernel when we log on to
a Unix system?
a) System
b) bash
c) shell
d) parent
View Answer
Answer: c
Explanation: As we log on to a UNIX system, a process is immediately
set up by the kernel. This process represents a UNIX command which
may sh (Bourne shell), ksh (Korn shell), csh (C shell) or bash (Bash).
This process remains alive until we log out when it is killed by the
kernel.
35. Which command shows some attributes of a process?
a) HOME
b) ps
c) $$
d) pid
View Answer
Answer: b
Explanation: ps command is used to show some attributes of a process.
This command reads through the kernel’s data structures and process
tables to fetch the characteristics of a process. By default, ps command
displays the processes owned by the user running the command.
36. Which of the following system call is used for creating a new process
in Unix?
a) new
b) wait
c) read
d) fork
View Answer
Answer: d
Explanation: A process in UNIX is created using fork() system call. It
creates an exact copy of the process that invokes it. Now there will be
two processes, one parent process and one child process. The process
which invokes the fork system call is called parent process and the new
process created is called child process.
37. Which of the following command is used to create a child shell?
a) sh
b) env
c) wait
d) fork
View Answer
Answer: a
Explanation: To create a child shell we can use the sh command. sh is
basically the command name of Bourne shell. sh is a command
language interpreter that executes commands read from a command
line string. To create a child shell, simply invoke sh command without
any argument.
38. Which Unix command is used for locating files?
a) type
b) loc
c) find
d) search
View Answer
Answer: c
Explanation: find is one of the most powerful tools of the UNIX system.
It recursively examines a directory tree to look for file matching based
on some criteria and then takes some action on the selected files.
39. Which command is used for preparing a file for printing?
a) pr
b) print
c) cat
d) cd
View Answer
Answer: a
Explanation: The pr command is used for preparing a file by adding
suitable headers, footers and formatted text. This command is used with
a filename as an argument. For example,
$ pr [Link]
May 06 10:38 1998 [Link] Page 1
01:accounts:6213
02:admin:5423
03:marketing:6521
04:personnel:2365
.....blank lines.......
40. Which command is used for sorting a file on specified fields?
a) pr
b) cut
c) tail
d) sort
View Answer
Answer: d
Explanation: Sorting is the ordering of data in ascending or descending
order. The sort command is used for ordering a file. Like cut command,
sort also identifies fields and perform sorting on specified fields. To
sort any file, just provide the name of the file as an argument with sort
command.
$ sort [Link]
41. Which Unix command is used for locating repeated and non-repeated
lines?
a) cut
b) paste
c) uniq
d) sort
View Answer
Answer: c
Explanation: When we concatenate or merge files, we can encounter
the problem of duplicate entries creeping in. UNIX offers a special
command (uniq) which can be used to handle these duplicate entries.
We can also use the sort -u command for doing the same piece of work.
42. Which command is used for translating characters?
a) paste
b) tr
c) trans
d) sort
View Answer
Answer: b
Explanation: The translate (tr) filter is used for manipulating individual
characters in a line. Usually, tr command translates characters using
one or two compact expressions. The syntax for using tr command is,
$ tr options expression1 expression2 standard input
43. Which of the following command will be used for searching
“director” in [Link]?
a) grep “director” [Link]
b) grep -director [Link]
c) grep -v “director” [Link]
d) grep “director”
View Answer
Answer: a
Explanation: Because grep command is also a filter, it can search it’s
standard input for the pattern. For example, the command grep
“director” [Link] will search the file [Link] for the pattern “director”
and will display the lines containing this pattern.
44. Which of the following command is used for searching for a pattern
in one or more file(s)?
a) paste
b) grep
c) cd
d) cp
View Answer
Answer: b
Explanation: UNIX has a special family of commands for handling
search requirements, and the principal member of this family is the
grep command. This command scans its input for a pattern and displays
the lines containing the pattern, the line numbers or filenames
containing the pattern.
45. Which of the following commands is known as stream editor?
a) grep
b) tr
c) sed
d) td
View Answer
Answer: c
Explanation: sed is a multipurpose tool which performs the function of
several filters together. This filter is derived from the ed (original
UNIX editor). It performs non-interactive operations on a data stream.
It uses instructions to act on a text for selecting lines, with an action to
be taken.
46. What is a shell script?
a) group of functions
b) a file containing a series of commands
c) a file containing special symbols
d) group of commands
View Answer
Answer: b
Explanation: When we have to execute a series of commands altogether,
we store them in a file which is itself executed as a shell script. A shell
script is basically a computer program designed to be run by the UNIX
shell.
47. To run the script, we should make it executable first by using _____
a) chmod +w
b) chmod +rwx
c) chmod +x
d) chmod +r
View Answer
Answer: c
Explanation: Before we run the script, it is essential to make the script
executable first. After that invoke the script name to run the script. For
making the script executable, we have to use chmod +x script_name.
48. Which command is used for acquiring superuser status?
a) su
b) pu
c) super
d) admn
View Answer
Answer: a
Explanation: Any user can acquire the status of superuser by using the
su command. The only condition that needs to be fulfilled here is,
he/she must be aware of the root password. For example,
$ su
Password: ***** //root’s password
#pwd
/home/abd //prompt changes ( super user mode)
49. Which command is used to find out the consumption of a specific
directory?
a) mem
b) dv
c) du
d) df
View Answer
Answer: c
Explanation: Sometimes, we may need to find out the consumption of a
specific directory rather than an entire file system. For this purpose, du
command is used. This command reports usage by recursive
examination of the directory structure.
50. Which filter apart from perl, is the most powerful?
a) awk
b) grep
c) cut
d) sed
View Answer
Answer: a
Explanation: The awk command made a later entry in the UNIX system.
Like sed, it combines features of several filters. It is one of the most
powerful filter after perl.
51. For running a Unix command within awk, we’ve to use ____ function.
a) split
b) system
c) substr
d) length
View Answer
Answer: b
Explanation: For running a UNIX command within awk, we’ve to use
system function. For example,
BEGIN
system(“date”) // prints the system date
52. To extract specific columns from a file ____ command is used.
a) cut
b) pr
c) head
d) tail
View Answer
53. Which of the following cannot be performed by cat command?
a) appending files
b) deleting files
c) creating files
d) displaying files
View Answer
Answer: b
Explanation: cat command cannot delete files. It can only be used for
viewing file contents, creating a file or appending to an existing file.
54. What is the default delimiter used by the cut command for cutting
fields?
a) underscore
b) space
c) tab
d) double tab
View Answer
Answer: c
Explanation: To extract useful data from a file, we use the cut
command to cut fields rather than columns. The cut command uses tab
as the default delimiter to cut fields.
55. Which of the following is not an internal command used by mailx?
a) d
b) N
c) a
d) q
View Answer
Answer: c
Explanation: There are various internal commands used by mailx each
of which performs a specified task.
N , prints the message numbered N
d , deletes the current message( if N is not specified along with it)
q , quits the mailx program
Unix Questions and Answers – Comparing Files:comm, cmp and diff
Command
« Prev
Next »
This set of Unix Multiple Choice Questions & Answers (MCQs) focuses
on “Comparing Files: comm, cmp and diff Command”.
1. Which command is used for comparing two files?
a) cmp
b) comp
c) diff
d) comm
View Answer
Answer: a
Explanation: cmp command is used for comparing two files byte by
byte. It displays the first mismatch and its location on the terminal. It
does not bother about subsequent mismatches but displays only the first
mismatch. As soon as the first difference is found, the command
terminates and outputs the line and byte in which there is a difference.
For example,
$ cmp file01 file02
file01 file02 differ: Byte 20, Line 2
diff command is used for converting one file into another in order to
make them identical and comm is used for displaying the common
elements in both the files.
Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
2. What is the exit status of cmp command if both the files are identical?
a) 0
b) 1
c) 2
d) undefined
View Answer
Answer: a
Explanation: The exit status of cmp command is 0 if both the files are
identical and 1 if both the files are different. The exit status is 2 if the
program encounters a problem.
3. Which option is used with cmp command to display a detailed list of
mismatches?
a) -a
b) -b
c) -f
d) -l
View Answer
Answer: d
Explanation: cmp command by default only displays the first mismatch
that occurs in both files. For a detailed list of all the mismatches, we
use the -l option. It prints byte position and the byte value for all
differing bytes.
Take Unix Tests Now!
4. Which option is used with cmp command to limit the number of bytes
to be compared?
a) -n
b) -l
c) -f
d) -b
View Answer
Answer: a
Explanation: We can limit the number of bytes to be compared by the
cmp command by using -n option with it. For example, if we want to
compare at most 50 bytes then the command will be written as:
$ cmp -n 50 file01 file02
5. How can we skip some initial bytes from both the files to be compared?
a) using -b option
b) using -n option
c) using -l option
d) using -i option
View Answer
Answer: d
Explanation: We can skip the number of initial bytes to be compared
from both the files such that the cmp command will not consider that
number of bytes while comparing both files. For this facility, we use -i
option followed by the number of bytes to be skipped. For example, to
skip the first 10 bytes use the following command,
cmp -i 10 file01 file02
6. -b option is used with cmp command to print the differing bytes in both
files.
a) True
b) False
View Answer
7. Which command compares two sorted files line by line?
a) cmp
b) diff
c) comm
d) sort
View Answer
Answer: c
Explanation: comm command is used for comparing two sorted files
line by line. When there is no option specified with comm command it
produces three column output. For example, if we want to compare two
files namely file01 and file02 then the first column will contain those
entries which are unique to file01 whereas the second column will
contain those entries which are unique to file02. The third column will
contain the actual information i.e. those entries which are common to
both fil01 and file02.
$ comm file01 file02
Sanfoundry
Project
Global
Learning
UNIX
In the above output, ‘Sanfoundry’ and ‘Learning’ are unique in file01
while ‘Global’ and ‘UNIX’ are unique in file02 whereas ‘Project’ is
common to both the file.
8. What will be the command if we want to suppress column 1 and
column 2 in the output of comm Command?
a) comm -12
b) comm -1-2
c) comm -3
d) comm -1,-2
View Answer
9. For comm command to work properly, files specified should be sorted.
a) True
b) False
View Answer
10. Which command is used to display the differences between files?
a) comm
b) diff
c) cmp
d) differ
View Answer
Answer: b
Explanation: diff command is used for comparing files and displaying
the differences between them.
diff command uses certain symbols and instructions to indicate the
changes that are required to make two files identical. For example,
a – for appending
c – for changing
d – for deleting
11. When two files are identical, what is the output of diff command?
a) Files are identical
b) Returns prompt
c) No output
d) Throws an error
View Answer
12. Which option is used to produce multi columnar output in diff
command?
a) -y
b) -v
c) -s
d) -e
View Answer
Answer: a
Explanation: -y option when used with diff command produces output
in multiple columns. For example,
$ diff -y file01 file02
Hii Hii
Hello | Hell
world world
Here ( | ) symbol indicates that the lines are different in both files.
13. If we are interested in knowing that whether the two files are identical
or not, we can use ___ command.
a) comm
b) diff
c) cmp
d) differ
View Answer
Answer: c
Explanation: All the three commands comm, diff and cmp are used for
comparing files but if we are interested in knowing whether two files
are identical or not we can use comm command without any option. It
will simply return the prompt without displaying any output if both the
files are identical.
Unix Questions and Answers – Comparing
Files:comm, cmp and diff Command
« Prev
Next »
This set of Unix Multiple Choice Questions & Answers (MCQs) focuses
on “Comparing Files: comm, cmp and diff Command”.
1. Which command is used for comparing two files?
a) cmp
b) comp
c) diff
d) comm
View Answer
Answer: a
Explanation: cmp command is used for comparing two files byte by
byte. It displays the first mismatch and its location on the terminal. It
does not bother about subsequent mismatches but displays only the first
mismatch. As soon as the first difference is found, the command
terminates and outputs the line and byte in which there is a difference.
For example,
$ cmp file01 file02
file01 file02 differ: Byte 20, Line 2
diff command is used for converting one file into another in order to
make them identical and comm is used for displaying the common
elements in both the files.
Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
2. What is the exit status of cmp command if both the files are identical?
a) 0
b) 1
c) 2
d) undefined
View Answer
Answer: a
Explanation: The exit status of cmp command is 0 if both the files are
identical and 1 if both the files are different. The exit status is 2 if the
program encounters a problem.
3. Which option is used with cmp command to display a detailed list of
mismatches?
a) -a
b) -b
c) -f
d) -l
View Answer
Answer: d
Explanation: cmp command by default only displays the first mismatch
that occurs in both files. For a detailed list of all the mismatches, we
use the -l option. It prints byte position and the byte value for all
differing bytes.
Take Unix Tests Now!
4. Which option is used with cmp command to limit the number of bytes
to be compared?
a) -n
b) -l
c) -f
d) -b
View Answer
Answer: a
Explanation: We can limit the number of bytes to be compared by the
cmp command by using -n option with it. For example, if we want to
compare at most 50 bytes then the command will be written as:
$ cmp -n 50 file01 file02
5. How can we skip some initial bytes from both the files to be compared?
a) using -b option
b) using -n option
c) using -l option
d) using -i option
View Answer
Answer: d
Explanation: We can skip the number of initial bytes to be compared
from both the files such that the cmp command will not consider that
number of bytes while comparing both files. For this facility, we use -i
option followed by the number of bytes to be skipped. For example, to
skip the first 10 bytes use the following command,
cmp -i 10 file01 file02
6. -b option is used with cmp command to print the differing bytes in both
files.
a) True
b) False
View Answer
7. Which command compares two sorted files line by line?
a) cmp
b) diff
c) comm
d) sort
View Answer
Answer: c
Explanation: comm command is used for comparing two sorted files
line by line. When there is no option specified with comm command it
produces three column output. For example, if we want to compare two
files namely file01 and file02 then the first column will contain those
entries which are unique to file01 whereas the second column will
contain those entries which are unique to file02. The third column will
contain the actual information i.e. those entries which are common to
both fil01 and file02.
$ comm file01 file02
Sanfoundry
Project
Global
Learning
UNIX
In the above output, ‘Sanfoundry’ and ‘Learning’ are unique in file01
while ‘Global’ and ‘UNIX’ are unique in file02 whereas ‘Project’ is
common to both the file.
8. What will be the command if we want to suppress column 1 and
column 2 in the output of comm Command?
a) comm -12
b) comm -1-2
c) comm -3
d) comm -1,-2
View Answer
9. For comm command to work properly, files specified should be sorted.
a) True
b) False
View Answer
10. Which command is used to display the differences between files?
a) comm
b) diff
c) cmp
d) differ
View Answer
Answer: b
Explanation: diff command is used for comparing files and displaying
the differences between them.
diff command uses certain symbols and instructions to indicate the
changes that are required to make two files identical. For example,
a – for appending
c – for changing
d – for deleting
11. When two files are identical, what is the output of diff command?
a) Files are identical
b) Returns prompt
c) No output
d) Throws an error
View Answer
12. Which option is used to produce multi columnar output in diff
command?
a) -y
b) -v
c) -s
d) -e
View Answer
Answer: a
Explanation: -y option when used with diff command produces output
in multiple columns. For example,
$ diff -y file01 file02
Hii Hii
Hello | Hell
world world
Here ( | ) symbol indicates that the lines are different in both files.
13. If we are interested in knowing that whether the two files are identical
or not, we can use ___ command.
a) comm
b) diff
c) cmp
d) differ
View Answer
Answer: c
Explanation: All the three commands comm, diff and cmp are used for
comparing files but if we are interested in knowing whether two files
are identical or not we can use comm command without any option. It
will simply return the prompt without displaying any output if both the
files are identical.