Unix Questions and Answers – Vi-Ex Mode – 2

This set of Unix Questions and Answers for Freshers focuses on “Vi-Ex Mode – 2”.

1. Quit (:q) command doesn’t work if the buffer is unsaved.
a) True
b) False
View Answer

Answer: a
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

Answer: c
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

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

4. In ex-mode, last line is represented by ___
a) :
b) $
c) >
d) .
View Answer

Answer: b
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

Answer: a
Explanation: Apart from saving our editing, we can use ‘:w’ command for writing selected lines. For example,

Note: Join free Sanfoundry classes at Telegram or Youtube
: 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

Answer: c
Explanation: To write selected line(s) to another file, we can use ex-mode command ‘:w’ along with the line number and filename.
advertisement

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

Answer: b
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

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

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

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

Answer: a
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

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

Answer: a
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 for Freshers, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.