250+ TOP MCQs on Operator-Command Combinations and Answers

Unix Multiple Choice Questions on “Operator-Command Combinations”.

1. An operator can’t perform any function without being combined with a command or itself.
a) True
b) False

Answer: a
Clarification: An operator alone cannot perform any function unless it is combined with a command or itself. For example, by using dd or yy we can delete or copy a line respectively.

2. For deleting the line form current cursor to the end of the line, we can use:
a) $
b) d$
c) dd
d) $d

Answer: a
Clarification: dd command is a combination of the d operator with itself. vi can perform complex deletion when this operator is combined with a command of the command mode. For example,

d$        //delete entire line fro current cursor location to end of line

3. dw will ________
a) deletes one line
b) deletes one word
c) deletes one character
d) deletes one sentence

Answer: b
Clarification: dd command is a combination of the d operator with itself. vi can perform complex deletion when this operator is combined with a command of the command mode. For example,

dw            // deletes one word
3dw           // deletes 3 words

4. For yanking text, ___ is used.
a) d
b) y
c) c
d) G

Answer: b
Clarification: The y operator is used for yanking (copying) text. It is used in the same way as d operator is used i.e. it is also combined with itself or with another command. For example,

5. For pasting text, ____ is used.
a) p or P
b) d or D
c) C
d) x or X

Answer: a
Clarification: After yanking text with yy, we can paste it using either p or P. p paste the text below the current line while P paste the text above the current line.

6. c operator is used for changing the text.
a) True
b) False

Answer: a
Clarification: For changing text, c operator is used. This operator is also combined with a command to perform the replacement. If dw deletes a word, cw changes it. This operator works in input mode. For example, to change the text from the present cursor location up to the end of line, use
c$ or C

7. To change entire lines, ____ is used.
a) cc
b) CC
c) dd
d) c$

Answer: a
Clarification: For changing text, c operator is used. This operator is also combined with a command to perform the replacement. To change entire lines, use the cc command.

8. Which operator is used in vi to filter text?
a) %%
b) &&
c) $
d) !

Answer: d
Clarification: vi provides a marvellous feature of allowing UNIX filter to act on the text that’s displayed on the terminal. For filtering text screen,
1. move to the beginning of the text to be acted upon and press !
2. move to the other end of the text using navigation command like G
3. Enter the command to act on the text.

9. To delete from current cursor upto the first occurrence of }, which of the following will be used?
a) dd$}
b) d /
c) d / }
d) }

Answer: c
Clarification: We can perform many functions using operator-command combinations. For example, d / } will deletes from the current cursor upto first occurrence of } .

10. The command df. will _____
a) deletes entire line
b) deletes entire paragraph
c) deletes from current cursor up to first occurrence of
d) deletes zero lines

Answer: c
Clarification: The command df. is another example of operator-command combination. It deletes from cursor to first occurrence of a dot.

11. To yank from current cursor up to first occurrence of string str in reverse direction, we can use:
a) y?str
b) y!str
c) yy str
d) yy ! str

Answer: a
Clarification: The command y?str is another example of operator-command combination. The operator ? is used with y operator for yanking a string in reverse direction.

12. The following command will_________

!! tr ‘[a-z]’  ‘[A-Z]’

a) throw an error
b) undefined behavior
c) changes the case of the current line from lower to uppercase
d) changes the case of current line from upper to lowercase

Answer: c
Clarification: The ! operator when doubled is used for operating on current line. For example, we can change the case of current line from lowercase to uppercase by using the above command.

13. The command c0 will change the text from current cursor to the end of line.
a) True
b) False

Answer: b
Clarification: The command c0 will change the text from current cursor to the beginning of line.

14. To sort all lines from current cursor to end of line, ____ can be used.
a) sort .,$
b) sort !G
c) sort !,G
d) !Gsort

Answer: d
Clarification: The sort command is combined with ! and G operator for sorting from current cursor to the end of the line.

15. Which of the following is not a valid operator-command combination?
a) 5dd
b) yy5
c) cc
d) yG

Answer: b
Clarification: The command yy5 is not a valid one as we cannot prefix the command yy with an integer value.

Leave a Reply

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