Linux-03- command

A common command

1, common operations

mkdir -p ./a/b/c // recursively create a multi-layer directory

mkdir ./abc/{,x,y,z}dir // create xdir at abc, ydir, cdir folder

cd ~ syraer // enter the user directory under the user name syraer

cd - before // Back to Contents

rm -f // forced to delete

rm -rf // recursive forced to delete

Clear Cache command hash -r //

mv 1 2 // move files -> directory

cp -r / a // copy files directory

ln 1 2 // hard link (point to the same address location, the count increases or decreases, delete files, count-down)

ln -s 1 2 // soft links (point to the same file, counting only increase not decrease. delete files, link error)

stat ./etc // metadata (modify permissions and other metadata information, change the time change. modify files, metadata changes, access time, file changes, three times will change)

touch // mainly used to modify metadata or three times to create an empty file

[root@node01 /]# stat /etc
  File: `/etc'
  Size: 4096      	Blocks: 8          IO Block: 4096   directory
Device: 803h/2051d	Inode: 917505      Links: 61
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-01-12 22:18:34.983663970 +0800
Modify: 2020-01-12 20:50:46.470668281 +0800
Change: 2020-01-12 20:50:46.470668281 +0800

 2, view file

cat // View Files

more // view files

less // view the file, q to exit, j line by line, b rollback, a piece of space

Former head -4 // View Files four lines

After the tail -4 // View Files four lines

grep PATTERN profile // Find the profile PATTERN

grep -v PATTERN profile // Find the profile does not contain PATTERN 

'|' Pipe format: a command | two command (a command output to a pipe, then two pipeline operation command) subsequent careful Science

echo "/" | xargs ls -l  //字符‘/’ 被命令xargs执行,把获取的字符‘/’当做ls命令的参数并执行ls

. 3, VI / Vim command (commonly marked red, must be used)

open a file

  • vim /path/to/somefile
  • vim + #: Open the file, and located in the first row # 
  • vim +: Open File, navigate to the last row
  • vim + / PATTERN: open a file, the first line is positioned to the first row is matched to the PATTERN
Full screen editor
Mode:
- Edit mode: keys with text editing functions: to enter edit mode by default
- Input mode: key significance in itself
- line mode: accept user input commands

Edit mode 

Edit -> Input:
I: in front of the current cursor characters into the input mode;
A: after the current cursor characters into the input mode;
O: below the current cursor line, the new line, and into the input mode;
-   O : the line above the current cursor, the new line, and into the input mode; 
the I : In the first line of the current cursor row, converting the input mode
A : In the end of the current cursor line, into an input mode
Input -> Editor:
ESC
Edit -> the last line :
the last line -> Editor:
- ESC ESC
Move the cursor
- Character
H: Left ; J: under ; k: on ; L: Right
- word
w: move to the next word of the first word
E: skip to the ending of the current or next word
b: Skip the current or previous word of the first word
- row
0: absolute beginning of the line
^: the first non-whitespace characters of
$: absolute end of the line
- between the lines
G: end of the article
3G: The first 3 lines
GG: beginning of the article
- scroll
ctrl f b
Delete & replace a single character
- the X-: delete the character at the cursor position
- 3x: Delete cursor starts 3 characters
- R & lt: Replace character cursor position
Delete command: d
- DW , dd, 3dw (three words)
Copy Paste & Cut 
- is , yy
p
P
Undo & Redo
- U   revocation
- Ctrl + R & lt   redo the undone action
- Operation Repeat the previous step

 Line mode

Close the file
line mode: shift +:

  • : Q Quit untouched file
  • : Wq to save and exit move over, do not regret it
  • :! Q to exit without saving move too, regret
  • : W save
  • :! W forced to save
  • :wq --> :x
  • shift + ZZ: colon does not need to save and exit edit mode 
  • the SET : Set
set nu  number
set nonu nonumber
set readonly
  • / : Find
/after
n N
- ? Look up
-1, $ d delete a row to the last row, a combination of command
  • ! :Excuting an order
- :! Ls -l /
  • s Find and Replace
- s / str1 / str2 / gi
/ : near s first character of command boundary characters: / , @ , #
G : one line Replace All
i : ignore case
- range
the n- : line number
. : Current cursor line
+ n : Offset n rows
$ : end of the line, $ -3
% : full text
Published 112 original articles · won praise 31 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_39531549/article/details/103945941