LFCA practice question 14 of 15
When using vi or vim to edit a file, how do you exit without saving?
Full set: 60 questionsDomain System Administration Fundamentals
In the vi or vim editor, commands are issued in command-line mode, which is accessed by pressing the colon (:) key. The command :q! is used to exit the editor without saving any modifications made to the file. The q stands for "quit," and the exclamation mark (!) is a force modifier that instructs the editor to discard all changes since the last save and terminate the session. This is the standard and correct method to abort an editing session and revert to the last saved state of the file.
B. ZZ: This command saves the file if it has been modified and then exits. It is equivalent to the :wq command, not a quit-without-saving action.
C. :wq!: This command forces a write (save) to the file, even if it's read-only (permissions allowing), and then quits. It explicitly saves changes.
D. :exit: This command, an alias for :x, saves the file only if it has been modified and then exits. It is a "save and exit" command, not a "discard and exit" command.
1. Vim Official Documentation (User Manual): In the section on exiting, the manual explicitly states: "To throw away your changes, use: :q!".
Source: Bram Moolenaar, Vim User Manual, usr10.txt, Section 10.2 "Exiting". Available at: https://vimdoc.sourceforge.net/htmldoc/usr10.html#10.2
2. Linux Man Pages (vi): The official manual page for vi describes the :q! command as the way to quit and discard all changes.
Source: vi(1) Linux manual page. Under the "Exiting vi" or "Commands" section, it specifies: ":q!" - Quit vi, discarding all changes."
3. Stanford University Courseware (CS 107): The course materials for Programming Paradigms include a guide to essential tools, which lists vi/vim commands.
Source: Stanford University, CS 107 Programming Paradigms, "Using Vim". The command list specifies: ":q!" - Quit without saving changes. Available at: https://web.stanford.edu/class/cs107/guidevim.html
Keep practicing
Take the free LFCA practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other LFCA practice questions
- Question 1Which measures can be taken to prevent unauthorized access to cloud instances and service…
- Question 2Which of the following is considered a best practice for hardening SSHD?
- Question 3An IT team needs to synchronize large amounts of data between two nodes on the company’s …
- Question 4Which of the following commands can be used to lock a user’s account so that they cannot …
- Question 5Which of the following best describes serverless computing?
- Question 6A server on the network is unreachable. What is the best method to verify connectivity be…
