This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Vi-Ex Mode – 2”.
1. Quit (:q) command doesn’t work if the buffer is unsaved.
a) True
b) False
View Answer
Explanation: Quit command has a safety mechanism that prevents us from aborting if the contents of the buffer are modified but not saved.
2. Which of the following command will be used if we want to abort editing and quit the editor even if the buffer has been changed and not saved?
a) :q
b) :b
c) :q!
d) :w
View Answer
Explanation: If the buffer has been changed and we still want to abandon the changes, then ‘:q!’ is used. It simply ignores all the changes made and quits without displaying any warning questions.
3. In ex-mode, current line is represented by ___
a) :
b) $
c) >
d) .
View Answer
Explanation: In ex-mode, the current line is represented by a (.) while : is used to invoke the ex-mode commands. The > is a redirection symbol used for redirecting output to a specified file.
4. In ex-mode, last line is represented by ___
a) :
b) $
c) >
d) .
View Answer
Explanation: To represent the last line in ex-mode, ‘$’ is used.
5. ‘:w’ command can be used to write selected lines.
a) True
b) False
View Answer
Explanation: Apart from saving our editing, we can use ‘:w’ command for writing selected lines. For example,
: 1,40w file002 //writes line number 1 - number 40 to another file named file002. : 1,$w file002 // writes line number 1 - last line to another file named file002.
6. Which of the following command will be used to write the 4th line to file named file002?
a) : 1,40w file002
b) : 1,$w file002
c) : 4w file002
d) : 1,4w file002
View Answer
Explanation: To write selected line(s) to another file, we can use ex-mode command ‘:w’ along with the line number and filename.
7. Which of the following is not a valid command?
a) : .,$w file002
b) :w 1,$ file002
c) : .w file002
d) : $w file002
View Answer
Explanation: First command will save from current line to the last line, the third command will save current line while the fourth command will save the last line in the file named file002.
8. How can we escape to the UNIX shell without quitting vi editor?
a) using ‘:sh’ command
b) using ctrl-Z
c) using ctrl-D
d) using ‘:sh’ command and using ctrl-Z
View Answer
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.
9. To return back to the editor from shell prompt we use _____ command.
a) fg
b) exit
c) back
d) fg and exit
View Answer
Explanation: To run to your editor, we can use either fg command or exit command. It depends on the way we escape to the UNIX shell. If we had escaped using ‘:sh’ then use exit command or ctrl-D to return to the editor and if you had used ctrl-Z then use fg command to return to the editor.
10. vi editor stores most of its information in a hidden swap file.
a) True
b) False
View Answer
Explanation: Accidents can happen while working on a system like a system or power failure. To recover from these kinds of issues vi stores most of its information in a hidden swap file. This file is removed on a successful exit from vi but it remains on the disk if there is an improper shutdown or power failure.
11. To recover from a crash, we can use ____ command.
a) :recover
b) -r
c) : x
d) :recover and -r
View Answer
Explanation: To recover from a crash, we can use either the ex-mode command :recover or vi -r filename to recover as much of filename as possible.
12. The following command will save the contents of the buffer and overwrites the contents of existing file.
:w! file003
a) True
b) False
View Answer
Explanation: Above command will work same like save as command in windows except that it will also replace the contents of file003 if it exists.
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Computer Science Internship
- Check Unix Books
- Practice MCA MCQs
- Check Computer Science Books
- Practice Computer Science MCQs