This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Filtering Commands – 1”.
1. Filter’s are a category of commands that take the advantage of shell redirection feature.
Explanation: Filters are defined as a category of commands that takes the advantage of shell’s redirection features. A filter is capable of reading standard input and writing to standard output. The piping mechanism is an example of a filter which lets the standard output of one filter to serve as standard input to another.
2. Which command is used for preparing a file for printing?
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 dept.lst May 06 10:38 1998 dept.lst Page 1 01:accounts:6213 02:admin:5423 03:marketing:6521 04:personnel:2365 .....blank lines.......
3. pr command adds ____ lines of margin at the top and bottom.
Explanation: pr command is used for preparing a file for printing by adding suitable headers, footers and formatted text. It adds five lines of margin at the top and five at the bottom. The header shows the date and time of last modification of the file along with filename and page number.
4. Which option is used with pr command for printing multi-columnar output?
Explanation: -k option is used with pr command (where k is an integer) for printing in k columns. For example, if a file contains a series of 12 numbers then we can divide the output into 3 columns in this way:
$ dept.lst | pr -3 May 06 10:38 1998 dept.lst Page 1 1 5 9 2 6 10 3 7 11 4 8 12
5. Which option is used with pr command to suppress the header and footers?
Explanation: We can use the -t option with pr command if we want to suppress the headers and associated which are displayed with the output of pr command. For example,
$ dept.lst | pr -t -5 // no headers and footers; multi-columnar output 1 5 9 2 6 10 3 7 11 4 8 12
6. Which option is used with pr command to display output along with line numbers?
c) -o n
Explanation: pr command offers many options which are used for producing the output in just the format we need. For example,
-d double spaces input
-n numbers lines, helps in debugging code
-o n offsets lines by n spaces, increases left margin of the page
$ pr -t -n -d -o 10 dept.lst 1 01:accounts:6213 2 02:admin:5423 3 03:marketing:6521 4 04:personnel:2365
7. -h option is used with pr command to add a header of our choice.
Explanation: If we are not using the -t option with pr command then we can use the -h option to add a header of our choice. This option is followed by the header string. For example,
$ pr -h “Department List” dept.lst
8. ___ operator is used with pr command to start printing from a specific page.
Explanation: There’s an option available with pr command which lets the user to print from a specific page number. This function is performed by prefixing a + with the page number. For example, to print from page number 5, use the following command:
$ pr +5 dept.lst
9. Which command is used for displaying the beginning of a file?
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 emp.lst
10. By default, how many lines are displayed using the head command?
Explanation: The head command, as the name suggests displays the top of the file. When this command is used without any option, it displays the first ten lines of the file.
11. Which option is used with the head command to specify line count to display?
Explanation: We can use the -n option with the head command to specify a line count and display a specific number of lines of the file. -n option is followed by an integer value which donates the number of lines to be displayed. For example,
$ head -n 3 emp.lst // displays first 3 lines of emp.lst
12. ___ command is used for displaying the end of the file.
Explanation: Complementing the head command, the tail command is used to display the end of the file. It provides an additional feature of addressing lines. By default, it displays the last ten lines of the file.
13. We can also use -n option with tail command.
Explanation: Alike head command we can also use the -n option with the tail command to specify the line count to be displayed from the end of the file. For example,
$ tail -n 3 emp.lst // displays last three lines
14. Which symbol is used with the tail command to print the file from the selected line?
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 emp.lst // start printing from 11th line onwards
15. Which of the following command is incorrect?
a) pr dept.lst
b) head -n 5 emp.lst
c) tail -o +5 emp.lst
d) tail -3 emp.lst
Explanation: The first command will prepare a file for printing by adding header, footers and formatted text. The command head -n 5 emp.lst will display the first 5 lines of emp.lst while the command tail -3 emp.lst will display the last 3 lines of emp.lst
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.