Multiple choice technology programming languages

How to open a file in read only mode using vi

  1. vi -R <filename>

  2. vi filename readonly

  3. vi -r

  4. Not possible

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The -R flag opens vi in read-only mode, preventing accidental modifications. Option B's 'readonly' is not a valid flag syntax, and option C's -r is for recovery mode after a crash. The 'view' command is equivalent to 'vi -R'.

AI explanation

To open a file in read-only mode in vi, use the uppercase flag: vi -R. This sets the 'readonly' option so the file can be viewed and edited in the buffer but not accidentally overwritten (though :w! can still force a save). Lowercase -r is a different flag used for recovering a file after a crash, not for read-only mode.