Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to Cloud Computing Development course: Linux heavy vi Editor

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Introduction to Cloud Computing Development course: Linux heavy vi Editor:

Create an exercise file

[root@tianyun ~] # ll-a > list.txt

File Editor gedit

File editors vi, vim, nano

Vi editor working mode

Command mode:

a. Cursor positioning

Hjkl

0 $

Gg G

3G enters the third line

/ string (n N can be cycled) quickly navigate to a line

/ ^ d

/ txt$

b. Text editing (a small amount)

Copy yy 3yy ygg yG (in behavior units)

D Delete dd 3dd dgg dG (in behavior units)

P paste

X Delete the character where the cursor is located

D delete from the cursor to the end of the line

U undo undo

^ r redo redo

R can be used to modify a character

c. Enter other modes

An enter insert mode

I enter insert mode

O enter insert mode

An enters insert mode

: enter the last line mode (extended command mode)

V enter visual mode

^ v enters visual block mode

V enters visual line mode

R enters replacement mode

Insert mode:

^ P

Visual block mode:

Block insert (character before specified block): select block, I insert character before block, ESC

Block replacement: select the block, r enter the character to replace

Block deletion: select block, d | x

Block copy: select block, y

Extended command mode:

a. Save exit

: 10 enter line 10

W save

Q exit

Wq saves and exits

: w! Forced save

: q! Do not save and exit

: wq! Force save exit

: X Save and exit ZZ

b. Find and replace

: range s/old/new/ option

: 1 s/root/yang/ 5 s/root/yang/ replaced by yang from 1 mi 5 lines of root

: 5 s/root/yang/ $represents the last line

: 1 s/root/yang/g $s/root/yang/g =:% s/root/yang/g% for full text g for global

:% s#/dev/sda#/var/ccc#g

:, 8 s/root/yang/ from the current line to line 8

4 replace the first # of line 9 / ^ # / 4-9 with a blank

Add # characters (. * whole line & reference lookup content) before 5-10.

c. Read / write file (save as)

W save to the current file

W / tmp/aaa.txt Save as / tmp/aaa.txt

: 1,3 w / tmp/2.txt

R / etc/hosts after reading the file to the current line

: 5 r / etc/hosts after reading the file to line 5

d. Set up the environment

Temporary settings:

: set nu sets the line number

Set ic is not case sensitive

: set ai automatic indentation

Set list display control character

: set nonu unsets the line number

: set noic

Permanent environment: modifying vim environment configuration fil

/ etc/vimrc affects all system users

~ / .vimrc affects a certain user

# vim ~ / .vimrc

Set ic

Set nu

Delete must use relative path, do not use absolute path

# vim-O / etc/hosts / etc/hostname ^ ww switch

# cp / etc/hosts hosts1

# vimdiff / etc/hosts hosts1

=

Create a file

[root@localhost ~] # touch aa.txt

[root@localhost ~] # touch aa.txt cc.txt tt.txt

[root@localhost ~] # touch abc {1.. 10} .txt

[root@localhost ~] # touch {areco bje c} {1.. 3} .txt

Create a directory

[root@localhost ~] # mkdir abc

[root@localhost ~] # mkdir abcd abce abcf

[root@localhost ~] # mkdir abc {1.. 5}

[root@localhost] # mkdir-p / root/aa/cc

[root@localhost] # mkdir-pv / root/aa/cc-p Recursive-v display process

Copy cp

Cp source file address destination address

[root@localhost ~] # cp / root/abc1.txt / tmp/

[root@localhost ~] # cp / root/abc1.txt / tmp/test.txt renaming during replication

Copy directory

[root@localhost] # cp-r / root/abcd/ / tmp/

[root@localhost ~] # cp-r / root/abcd/ / tmp/aaa rename

Cut mv

Cp source file address destination address

[root@localhost ~] # mv / root/tt.txt / tmp/

[root@localhost ~] # mv / root/tt.txt / tmp/back.txt

Move directory

[root@localhost ~] # mv / root/abcf/ / tmp/

[root@localhost ~] # mv / root/abcf/ / tmp/back

Delete rm rmdir

Rmdir can only delete empty directories

Rm

[root@localhost ~] # rm aa.txt

[root@localhost] # rm-f cc.txt

[root@localhost ~] # rm-rf abce/

[root@localhost ~] # rm-rf a1.txt a2.txt

[root@localhost] # rm-rf * .txt

[root@localhost ~] # rm-rf abc*

[root@localhost] # rm-rf *

[root@localhost ~] # rm-rf / install.log

View the contents of the file

Head

[root@localhost ~] # head / root/install.log

[root@localhost ~] # head-n 20 / root/install.log

[root@localhost] # head-20 / root/install.log

Tail

[root@localhost ~] # tail / root/install.log

[root@localhost] # tail-20 / root/install.log

[root@localhost ~] # tail-f / var/log/messages Monitoring Log File

More

[root@localhost ~] # more / root/install.log

The space goes back one page, enter back, b, forward.

Less

[root@localhost ~] # less / root/install.log

Cat

[root@localhost] # cat-n / root/install.log

[root@localhost ~] # cat-n aa.txt all lines

[root@localhost ~] # cat-b aa.txt valid line

[root@localhost ~] # cat-n / root/install.log | less

Exercise:

1. Create the following directory structure? And verify it? (an order?)

/ aa

/\

Bb/ bc/

/\\

Ca/ cb/ cc/

[root@localhost ftp] # mkdir-pv / aa/bb/c {ajar b} / aa/bb/cc

[root@localhost ftp] # mkdir-pv / aa/b {bplink c {a, b}, c/cc}

[root@localhost ftp] # ls-R / aa/

[root@localhost ftp] # tree / aa

/ aa

├── bb

│ ├── ca

│ └── cb

└── bc

└── cc

[root@localhost ftp] # tree-L 2 /-L level

two。 When / etc/man.config is copied to the ca directory (in two ways) the current directory /

[root@localhost ~] # cp / etc/man.config / aa/bb/ca/

[root@localhost /] # cp etc/man.config / aa/bb/ca/

3. Move the man.config under ca to the cc directory and rename it to test.txt (2) current directory bb

[root@localhost bb] # mv / aa/bb/ca/man.config / aa/bc/cc/test.txt

[root@localhost bb] # mv ca/man.config / aa/bc/cc/test.txt

4. Copy the same file to the same directory twice without an overwrite prompt

[root@localhost] #\ cp / root/install.log / tmp/

[root@localhost bb] # / bin/cp / root/install.log / tmp/install.log

[root@localhost bb] # unalias cp

[root@localhost bb] # cp / root/install.log / tmp/install.log

5. Show only line 1001 of the / root/install.log file

[root@localhost bb] # cat-n / root/install.log | head-1001 | tail-1

VIM text editor

Three basic modes of vim: command mode, input mode, and last line mode

Switch from command mode to input mode:

An enter after the current character

An input at the end of the current line

I enter before the current character

I current line header input

O input on the next line of the current line

O input on the previous line of the current line

S enter after deleting the current character

S enter after deleting the current line

In command mode

U undo one-step operation

Ctrl+r redo

Copy a line of yy paste p

Copy 50 lines of 50yy

Cut / delete a row of dd

Cut / delete 50 lines of 50dd

The beginning of the line

$end of line

D ^ Delete the current character to the beginning of the line

D $removes the current character to the end of the line

Y ^

Y $

Replace

: s/ab/**/ replaces the first string to which the current line matches

: s/ab/**/g replaces all matching strings on the current line s replaces g global

4. Open the new tab ctrl+shift+t alt+1. Toggle label ctrl+shift+w close tag ctrl+shift+q close all terminals

# commands are saved under bin

There are two ways to use Shell:

Inefficient input commands are suitable for a small amount of work

Shell Script (script) is efficient and suitable for complex and repetitive tasks.

Pwd displays the current full directory

# indicates that we are currently using a super account

$indicates that we are currently using an ordinary account

Long hostname: zhuangyao.baidu.com

Enter bash command considerations:

Enter the command:

# Command [option] parameter operator

# ls

All commands must be followed by spaces (the number of spaces is not online)

Tab: automatic completion

The reason why it is not completed: the command is miswritten and has no executable permission.

Ctrl+c: interrupts the current input

Common shortcut keys:

Ctrl + c: terminate the command

Ctrl + up and down: move by word

Move to the beginning of the command line home

Move to the end of the command line end

Thinking questions:

Delete from the cursor to the beginning of the command line

Delete from cursor to the end of the command line

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report