You opened a file with `vi -R /etc/motd`, so the editor's `readonly` option is set. You then decide the file does need changing, make your edits, and `:w` is refused with a message that the readonly option is set. Your account does have permission to write the file. Which command writes it anyway?

LPIC-1 Exam 101-500, objective 103. GNU and Unix commands medium

Machine-checked — no person has signed for it. This question was read against the source cited below by an automated pass, which found no contradiction. That is a weaker claim than it sounds: the same kind of process wrote the question, so it can confirm its own mistake.

Treat it as a good draft rather than as settled fact, and read the source below before you rely on it. It is not used in mock exams here — only questions a person has signed for are.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

The options

Correct :w!

Correct. A trailing `!` on the ex write command overrides the editor's own readonly guard and writes the file. vim(1) states this for the -R option: if you do want to overwrite the file, add an exclamation mark to the Ex command, as in `:w!`.

Not correct :q!

Wrong, and it loses the work. `:q!` quits and discards every unsaved change in the buffer.

Not correct :wq

Wrong. This is the same unforced write that has already been refused, with a quit appended; without the `!` the readonly option still blocks it. `:wq!` would have worked.

Not correct ZZ

Wrong. `ZZ` is the command-mode shortcut for write-and-quit, so it meets exactly the same refusal as `:wq`.

Why

In ex commands a trailing exclamation mark means force: `:w!` writes over the editor's readonly objection, `:q!` quits over its unsaved-changes objection. The readonly option is the editor's own caution — set by the -R option, by starting the editor as `view`, or automatically when the file carries no write permission for you — and `!` overrides that flag. What `!` cannot override is the kernel: if the filesystem permissions genuinely deny the write, `:w!` fails too, with an error about not being able to open the file for writing.

Where this comes from

Cited
manual page vim(1)

Practise this

Reading one question is not practice. The trainer will draw a short set from objective 103 and space the ones you get wrong.

Practise LPIC-1 Exam 101-500

More questions on this objective

All questions on GNU and Unix commands

Practise LPIC-1 Exam 101-500