System Administration PT1 Flashcards
(32 cards)
What is the difference between vi and vim?
vim
stands for ‘Vi IMproved’ and is an enhanced version of vi
. It includes features like syntax highlighting, multiple undo levels, and plugin support, which vi
lacks.
How do you open a file in vi or vim?
Use vi filename
or vim filename
in the terminal.
What are the modes in vi/vim?
- Normal mode (for navigation/commands)
- Insert mode (for editing text)
- Command-line mode (for saving, quitting, etc.)
How do you switch to Insert mode in vi/vim?
Press i
(insert), a
(append), or o
(open a new line).
How do you exit Insert mode in vi/vim?
Press Esc
to return to Normal mode.
How do you save and quit in vi/vim?
Press Esc
, then type :wq
and hit Enter
.
How do you quit without saving in vi/vim?
Press Esc
, then type :q!
and hit Enter
.
How do you search for text in vi/vim?
Press /
, then type the search term and hit Enter
.
How do you delete a line in vi/vim?
In Normal mode, type dd
.
What does the sed
command do?
sed
is a stream editor that can perform text transformations on an input stream (a file or input from a pipeline).
How do you use sed
to replace ‘apple’ with ‘orange’ in a file?
sed 's/apple/orange/g' filename
What does the g
flag mean in sed
?
It stands for ‘global’, meaning all occurrences in the line will be replaced.
How do you edit a file in place using sed
?
Use the -i
flag, e.g., sed -i 's/old/new/g' filename
How do you delete a specific line using sed
?
sed '3d' filename
deletes line 3.
How do you copy a line in vi/vim?
In Normal mode, use yy
to yank (copy) the current line.
How do you paste a copied line in vi/vim?
Use p
to paste after the cursor, or P
to paste before.
How do you undo and redo changes in vi/vim?
Use u
to undo and Ctrl+r
to redo.
How do you move to the beginning and end of a line in vi/vim?
Use 0
to move to the beginning and $
to the end.
How do you jump to a specific line number in vi/vim?
Use :linenumber
, e.g., :20
to jump to line 20.
How do you search and replace across the whole file in vi/vim?
Use :%s/old/new/g
How do you record and replay a macro in vi/vim?
Use q<letter>
to start recording, do actions, then press q
to stop. Replay with @<letter>
.
How do you set line numbers in vim?
In command mode, use :set number
.
How do you turn off line numbers in vim?
Use :set nonumber
.
What does :syntax on
do in vim?
Enables syntax highlighting.