250+ TOP MCQs on Counting File Data: wc Command and Answers

Unix Multiple Choice Questions on “Counting File Data: wc Command”.

1. Which command is used for counting words, lines and characters in a file?
a) diff
b) count
c) man
d) wc

Answer: d
Clarification: 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.

2. wc command cannot take multiple filenames as arguments.
a) True
b) False

Answer: b
Clarification: wc command can take multiple filenames as arguments. If multiple filenames are specified with wc command then it will produce a separate line of output for each file along with an additional line as a total count for all files specified. For example,

$ wc  file01  file02  file03
12    45      170    file01
8     34      145    file02
10    38      158    file03
30    117     403    total

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

Answer: a
Clarification: -l option when used with wc command display only the number of lines in the specified file.

$ wc  -l  file01
3        // number of lines in file01

4. Which option is used for counting the number of words in a file only?
a) -l
b) -W
c) -c
d) -w

Answer: d
Clarification: -w option when used with wc command display only the number of words in the specified file.

$ wc  -w  file01
15        // number of words in file01

5. Which option is used for counting the number of characters in a file only.
a) -l
b) -W
c) -c
d) -w

Answer: c
Clarification: -c option when used with wc command display only the number of characters in the specified file.

$ wc  -c  file01
45        // number of characters in file01

6. wc command can also work on a data stream.
a) True
b) False

Answer: a
Clarification: wc command when invoked without any special symbol ( like

$ wc
 Global
Learning project
Offer internships to students
Ctrl-D
3    8    65        // 3 lines, 8 words and 65 characters

7. 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

Answer: c
Clarification: > symbol can be used with wc command for redirecting output. For example, the following command will read the input from sample.txt and redirect its output to newfile.

$  wc  sample.txt >  newfile

8. Which command is used for printing a file?
a) lp
b) pr
c) pg
d) more

Answer: a
Clarification: lp command is used for printing a single copy of the file specified as an argument to lp command. For example,

Request id id prl-890 (1 file )
lp command notifies the request-id i.e. a combination of printer name(rpl) and job number (890).

9. Which option is used with lp command if there are more than one printers in the system?
a) -t
b) -d
c) -i
d) -p

Answer: b
Clarification: lp command prints the file as a default printer has been already specified by the system administrator. In case if there is more than one printer in the system we have to use the -d option with the printer name to print the file. For example, if there is another printer named laser_001 then,

10. Which option is used for printing multiple copies of a file using lp command?
a) -l
b) -i
c) -t
d) -n

Answer: d
Clarification: If we want to print multiple copies of a file, we can use the -n option followed by an integer i.e. the number of copies that we want to print. For example to print 5 copies of file abd.txt use the following command,

11. -t option prints the title on the first page.
a) True
b) False

Answer: a
Clarification: To print a specific title on the first page, we use the -t option followed by the string which we want to print as a title. For example,

$ lp  -t "UNIX and Shell programming"  abd.txt

12. What does the following command do?

a) cancel printing from printer ‘prl’
b) cancel printing current job
c) cancel printing job number 320 on printer name ‘prl’
d) undefined behavior

Answer: c
Clarification: cancel command is used to cancel the jobs submitted by the user for printing. cancel command can cancel the job only when it is in print queue i.e. waiting to be assigned to a printer. If the printer has already started processing the job, cancel command will not work.

13. Which command is used for knowing the file type?
a) file
b) type
c) filetype
d) type of file

Answer: a
Clarification: UNIX provides the file command for determining the type of file i.e. whether it is a text file, script file, archive file or any other type of file.

$ file  file01
file01:    Text file

14. file command identifies the file type by examining the magic number of the file.
a) True
b) False

Answer: a
Clarification: Magic number is the number which is embedded in the first few bytes of a file. Every file has a unique magic number which helps in identifying the file type.

15. UNIX offers a pager named ____ which has replaced the original pager of UNIX called ____
a) more, less
b) less, more
c) more, pg
d) pg, more

Answer: c
Clarification: The man command displays its output one page at a time. This is possible because it sends its output to a pager program. more pager is extensively used in UNIX system and it has replaced the original pager of UNIX i.e. pg. The task of a pager program is to simply display pages on the terminal. It can also be used to display the contents of a file.

$ more  abd.txt   // contents of the file named abd.txt will be displayed.

16. Which of the following is not an internal command for more?
a) q
b) f
c) b
d) z

Answer: d
Clarification: more pager offers a set of internal commands which are used for viewing pages differently. For scrolling one page at a time, use ‘f’ or the space bar. Similarly for scrolling backward press ‘b’ and for quitting the pager use ‘q’.

Leave a Reply

Your email address will not be published. Required fields are marked *