System Administration PT1 Flashcards

(32 cards)

1
Q

What is the difference between vi and vim?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you open a file in vi or vim?

A

Use vi filename or vim filename in the terminal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the modes in vi/vim?

A
  1. Normal mode (for navigation/commands)
  2. Insert mode (for editing text)
  3. Command-line mode (for saving, quitting, etc.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you switch to Insert mode in vi/vim?

A

Press i (insert), a (append), or o (open a new line).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you exit Insert mode in vi/vim?

A

Press Esc to return to Normal mode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you save and quit in vi/vim?

A

Press Esc, then type :wq and hit Enter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you quit without saving in vi/vim?

A

Press Esc, then type :q! and hit Enter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you search for text in vi/vim?

A

Press /, then type the search term and hit Enter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you delete a line in vi/vim?

A

In Normal mode, type dd.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the sed command do?

A

sed is a stream editor that can perform text transformations on an input stream (a file or input from a pipeline).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you use sed to replace ‘apple’ with ‘orange’ in a file?

A

sed 's/apple/orange/g' filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the g flag mean in sed?

A

It stands for ‘global’, meaning all occurrences in the line will be replaced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you edit a file in place using sed?

A

Use the -i flag, e.g., sed -i 's/old/new/g' filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you delete a specific line using sed?

A

sed '3d' filename deletes line 3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you copy a line in vi/vim?

A

In Normal mode, use yy to yank (copy) the current line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you paste a copied line in vi/vim?

A

Use p to paste after the cursor, or P to paste before.

17
Q

How do you undo and redo changes in vi/vim?

A

Use u to undo and Ctrl+r to redo.

18
Q

How do you move to the beginning and end of a line in vi/vim?

A

Use 0 to move to the beginning and $ to the end.

19
Q

How do you jump to a specific line number in vi/vim?

A

Use :linenumber, e.g., :20 to jump to line 20.

20
Q

How do you search and replace across the whole file in vi/vim?

A

Use :%s/old/new/g

21
Q

How do you record and replay a macro in vi/vim?

A

Use q<letter> to start recording, do actions, then press q to stop. Replay with @<letter>.

22
Q

How do you set line numbers in vim?

A

In command mode, use :set number.

23
Q

How do you turn off line numbers in vim?

A

Use :set nonumber.

24
Q

What does :syntax on do in vim?

A

Enables syntax highlighting.

25
What is the difference between `:wq` and `ZZ` in vim?
Both save and quit, but `ZZ` doesn't require pressing `:`.
26
How do you print only lines that match a pattern using `sed`?
`sed -n '/pattern/p' filename`
27
How do you delete all blank lines using `sed`?
`sed '/^$/d' filename`
28
How do you replace only the first occurrence in a line with `sed`?
`sed 's/old/new/' filename` (no `g` flag)
29
How do you use sed to edit multiple patterns?
`sed -e 's/one/1/g' -e 's/two/2/g' filename`
30
How do you save sed output to a new file?
`sed 's/old/new/g' filename > newfile.txt`
31
Can `sed` use regular expressions?
Yes, `sed` supports basic and extended regex patterns.
32
How do you replace a string that includes slashes in `sed`?
Use a different delimiter like `#`: `sed 's#/old/path/#/new/path/#g'`