Exam Prep Questions
-
What is the default editor for Linux systems?
-
emacs
-
joe
-
vi
-
pico
-
Which of the following saves and exits a file you are editing in vi? (Choose all that apply.)
-
:x
-
:q!
-
Shift+ZZ
-
zz
-
:wq
-
After opening a file with vi, you want to navigate to the end of the file as quickly as possible. Which of the following, when performed in Command mode, accomplishes this?
-
Ctrl+PgDn
-
Shift+G
-
Meta+End
-
Shift+End
-
On the line below, enter the vi command that would open the file mytestfile.txt and cause nonprinting line numbers to appear to the left of all file contents:
-
While editing a file with vi, you press Esc to enter Command mode and then use the keystrokes 3+J+4+L. What is the result?
-
Three columns left and four lines down
-
Three columns right and four lines up
-
Three lines up and four columns left
-
Three lines down and four columns right
-
Which of the following commands opens a file named file1.txt with nonprinting line numbers displayed in vi?
-
vi /set number file1.txt
-
vi +"set number" file1.txt
-
vi < .exrc file1.txt
-
vi "se nu" file1.txt
-
You want to edit a file with vi and have the word string1 highlighted if found. Which of the following accomplishes this in one command?
-
vi +/"string1" file
-
vi /string1 file
-
vi +/string1 file
-
vi --find string1 file
-
While editing a file in vi, you need to display the permissions for the normal files in the current directory. Which command accomplishes this from Command mode?
-
:x "ls l"
-
:e! ls -l
-
Shift+L+S+-+L
-
:! ls -l
-
You'll be editing the files in /project1 by executing vi from that location. You want a set of options to always be set for this project, and not other vi sessions. Which of the following files would you edit to best accomplish this?
-
/project1/.exrc
-
~/.vimrc
-
.virc
-
/etc/editorrc
-
While in vi, you need to search and replace all instances of the string snark with FARKLE in the current file. Write the answer on the line below, including everything necessary to accomplish this from Command mode:
Answer C is correct because vi is in nearly every distribution of Linux that exists. Answer A is incorrect because, even though emacs is very well known, it's considered an add-on to Linux. Answer B is incorrect because joe is a specialized editor and not normally included in a distribution by default. Answer D is incorrect because pico is used only for document-style text editing, and is not the default editor.
Answers A, C, and E are correct because they save and exit a given file in vi. Answer B is incorrect because it forces a nonsaving exit to a modified buffer or file. Answer D is incorrect because only a shifted pair of z characters saves and exits a file properly.
Answer B is correct because it takes the cursor to the end of the file. Answer A is incorrect because Ctrl+PgDn does nothing in vi. Answer C is incorrect because it moves to the end of the current line. Answer D is incorrect because it does nothing in vi.
__________________________________________________________________
The answer is vi +"set number" mytestfile.txt.
Alternative possible correct answers are
vi mytestfile.txt +"set number" vi mytestfile.txt "+set number"
Answer D is correct because the J key denotes the down arrow and the L character denotes the right arrow. Answers A, B, and C are incorrect because they don't use the correct keystrokes.
Answer B is correct because it turns on the line numbering. Answer A is incorrect because it has a slash (/) instead of a plus symbol (+). Answer C is incorrect because it either produces a syntax error or just edits the .exrc file. Answer D is incorrect because it's missing the necessary plus symbol (+).
Answer C is correct because it searches for and highlights the string string1 properly. Answer A is incorrect because it has added quotation marks around the search string. Answer B is incorrect because it's missing the necessary plus symbol. Answer D is incorrect because there is no --find option for vi.
Answer D is correct because it starts a subshell and displays the normal files in the current directory. Answer A is incorrect because it exits the file and ignores the ls command. Answer B is incorrect because it attempts to edit all the files returned by the ls command and errors out. Answer C is incorrect because it just starts displaying the text on the screen in vi.
Answer A is correct because it configures vi with the necessary options only if executed from the /project1 directory. Answer B is incorrect because the .vimrc file in question is located in the current user's home directory, not the project1 directory. Answer C is incorrect because the file named is a fake. Answer D is incorrect because no such file as /etc/editorrc exists.
__________________________________________________________________
The answer is :%s/snark/FARKLE/g. There are no alternative correct answers.