Linux basic commands (edit)

Linux basic commands (edit)

File system hierarchy

  • FHS: file system hierarchy

/: Root partition
/ Boot: system startup related documents, such as the kernel (vmlinuz), initrd (initramfs) and GRUB (the bootloader)
/ dev: device file, is not a separate partition
/ etc: Configuration file directory
/ Home: Common User Home
/ root: administrator home directory
/ lib: library directory
/ media: mount point directory, usually used to mount the mobile device
/ mnt: mount point directory, usually used to mount additional temporary file system, such as another piece HDD
/ opt: optional directory, by early to install third-party software
/ proc: pseudo file system, the kernel mapping file, not a separate partition
/ sys: pseudo file system, with hardware-related attribute mapping file, not a separate partition
/ tmp: temporary files directory
/ var: variable files, such as log, cache. Store log files, pid file, lock file
/ bin: executable file, a user command
/ sbin: Management command
/ usr: global shared read-only file. Provide core operating system features, you can separate partition
   / usr / bin
   / usr / sbin
   / usr / lib
/ usr / local: third-party software installation path
   / usr / local / bin
   / usr / local / sbin
   / usr / local / lib
   / usr / local / etc
   / usr / local / man
in the / etc, / bin, / sbin , / lib directory systems such as boot you need to use the procedure, these directories can not mount additional partitions must be on the root file system partition

/ usr / bin, / usr / sbin, / usr / lib provide core operating system functions, / usr can be divided into separate
/ usr / local / bin, / usr / local / sbin, / usr / local / lib, / usr / local / etc, / usr / local / man and much more in / usr / local directory of all third-party software, we recommend a separate partition

Redirect

  • System settings:
      default input device: standard input, STDIN, 0 (keyboard)
      the default output device: standard output, STDOUT, 1 (display)
      standard error: standard error, STDERR, 2 (display)

  • I / O redirection:
      >: Override Output
      >>: append output
      2>: Redirect error output
      &>: Redirect standard cover to the same output and error file
      <: input redirection
      <<: Here Document

    pipeline

    As the output of a command before a command input .

The last command will be executed in the current shell sub-shell process in the process.

Command 1 | command 2 | command 3 | ...

The tee command: read data from standard input, output to a screen, saved to a file

[root@localhost ~]# echo "hello world" | tee /tmp/hello.out 
hello world 
[root@localhost ~]# cat /tmp/hello.out 
hello world

Editor for Linux Introduction

  • Linux under common text editors are:
    • emacs
    • pico
    • nano
    • joe
    • jed
    • we

vi editor is essential on linux and unix text editor, working in character mode. Since no graphical interface, vi is a highly efficient text editor. Although there are many graphical editors available on linux, but vi and server management functions in the system are those graphics editor can not match.

vi editor can perform the output, delete, find, replace, block operations, and many other text operations, and users can customize it according to their needs, which is the other editing programs do not have.

vi enhanced version of vim is easier to use than vi. vi commands can be used almost in vim.


vi / vim features

  • vi / vim is a plain text editor, it is not possible word layout can adjust the font size, the font may be changed and so on.
  • vi / vim just a text editor, can only operate on the content of the text, such as new content, edit content, delete content, etc.
  • Full screen display

vi / vim three edit modes

  • Command Mode
  • Input Mode
  • Line mode
Edit mode effect
Command Mode The user executes a command, such as copy line, paste line, etc.
Input Mode For entering text, modified text, etc.
Line mode For finding text, save the changes, etc.

Between three kinds of edit mode vi / vim way conversion

  • Command mode -> Input Mode
     i: insert, in front of the current character of the cursor, turn the input mode
     I: uppercase i, the first line in the input mode is converted to the current cursor line
     a: append, the character in the current cursor position converted back to the input mode
     a: in the end of the current line of the cursor into an input mode
     o: open, create a new row below the current cursor row and into the input pattern
     O: uppercase O, not number 0, the current the cursor is located over a new row into an input mode, and

  • Input Mode -> Command Mode
    ESC

  • Command Mode -> line mode
    :

  • Line mode -> Command Mode
    ESC ESC

Open the file mode

After the file is opened in default under the command mode

vim filename // open file
vim + n filename // open the file and to locate the n-th row
vim + / pattern filename // open the file and to locate the first / pattern matched to the content of the line

Close papers

  • Close the file line mode:
command significance
q drop out
wq Save and Exit
q! Exit without saving
w Save without exiting
w! Forced to save
wq Forced to save and exit
x Forced to save and exit

Close papers

  • Close the file command mode :
    • ZZ

      Move the cursor manner

      Move the cursor mode Method of moving significance
      Character by character movement h Left one character
      l Move one character to the right
      j Move down one character
      k Move up one character
      #h Mobile # characters to the left
      #l # Characters to the right
      #j Characters move down #
      #k # Characters move up
      The word mobile units w Move to the next word of the first word
      e Skip to ending the current or next word
      b Skip the current or beginning of a word on a word
      #w Starting at the current cursor jumps to the first word of the first word #
      #e Starting at the current cursor jumps to the first word endings #
      #b Starting at the current cursor jumps to the first word of the first word #
      Jump in the Line 0 The numbers 0, jump to the absolute beginning of the line
      ^ Jump to the first non-whitespace characters of
      $ Jump to the absolute end of the line
      Jump between the lines gg Jump to the first line
      G Jump to the last line
      #gg Go to page # row
      #G Go to page # row
      Scroll ctrl+f Scroll down a screen
      ctrl+b Turn up one screen
      ctrl+d Scroll down half screen
      ctrl+u Turn up half screen

Character Editor

Edit command significance
x To delete a single character at the cursor
#x At cursor to delete characters and back of #
xp And exchanging positions of characters after the character at the cursor

Delete command: d

  • D command mode command and a jump command is often used in combination, such as
      d $: delete the current cursor position indicates the end of the row content to
      d ^: delete the current content indicates cursor position to the first row of the first non-blank character position
      d0 : deletes the contents of the current cursor position to the absolute beginning of the line
  • #d跳转符:删除跳转符指定范围内的#个,例如
      #dw
      #de
      #db
      dd:删除当前光标所在行整行
      #dd:删除包括当前光标所在行在内的#行
      D:删除当前光标所在行的内容,保留空行
  • 删除命令:d
    • 末行模式下d命令的使用
        :StartADD,EndADDd  
    • 这里的StartADD与EndADD是指一个范围,例如:
        1,5d:表示删除第1到第5行
  • 范围表示方法
表示方法 意义
. 光标所在当前行
$ 最后一行
+# 光标所在行往后#行
$-# 倒数第#行
% 全文

复制与粘贴

  • 复制命令:yy

  • 粘贴命令:p
    p:小写p
    若删除或复制的为整行内容,则粘贴至光标所在行的下方
    若删除或复制的为非整行,则粘贴至光标所在字符的后面
    P:大写p
    若删除或复制的为整行内容,则粘贴至光标所在行的上方
    若删除或复制的为非整行,则粘贴至光标所在字符的前面

替换、撤销编辑与重复编辑操作

  • 替换:r
    R:替换模式,替换多个字符
    r#:将当前光标的字符替换为#,这里的#可以是任何字符

  • 撤销编辑:u
    u:撤销前一次的编辑操作,连接u命令可以撤销此前的n次编辑操作
    #u:直接撤销此前的#次编辑操作
    ctrl+r:还原最近一次的撤销操作

  • 重复前一次编辑操作:.
    .

    可视化与文本查找

  • 可视化模式:可视化模式下可以对选取的内容进行前面讲的所有编辑操作
    v:按字符选取内容
    V:按矩形块(行)选取内容

  • 文本查找:
    /pattern:从上往下查找匹配的内容
    ?pattern:从下往上查找匹配的内容
    n:从上往下查找匹配到的内容的下一条
    N:从下往上查找匹配到的内容的下一条

    查找并替换与行号控制

  • 查找并替换:s
    s命令只能在末行模式下使用,语法如下:
      :ADDR1,ADDR2 s/pattern/string/gi

  • 示例:
    :1,5 s/abc/def/g 表示把第一行到第五行的所有abc替换为def

  • 末行模式下显示或取消显示行号:
    set nu:显示行号
    set nonu:取消显示行号

Guess you like

Origin www.cnblogs.com/guilai/p/11543584.html