The unix command : $ vi file1 file2

2015

The unix command : 

$ vi file1 file2

  1. A.

    Edits file1 and stores the contents of file1 in file2

  2. B.

    Both files i.e., file1 and file2 can be edited using 'ex' command to travel between the files

  3. C.

    Both files can be edited using 'mv' command to move between the files

  4. D.

    Edits file1 first, saves it and then edits file2

Attempted by 39 students.

Show answer & explanation

Correct answer: B

Answer: vi file1 file2 opens both files and lets you edit either by switching between them.

Key points and useful commands:

  • Open multiple files: vi file1 file2 — both files are placed in vi's argument/buffer list.

  • Go to the next file: :n.

  • Go to the previous file: :prev (or :N).

  • List the files in the argument list: :args.

  • Edit a specific file from inside vi: :e filename.

  • Write current buffer to another filename (copy contents): :w file2.

Why the other choices are wrong:

  • The idea that opening both files stores the contents of the first into the second is false; no automatic copy occurs.

  • Using mv is irrelevant for switching inside the editor; mv renames or moves files at the filesystem level.

  • You do not have to save file1 before editing file2 when both are opened; vi lets you switch, though unsaved changes may prompt you or require forcible commands to discard.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…