Linux series common commands (directory and file management) vi and vim editor use, (notes)

  • About the author: A cloud computing network operation and maintenance personnel, sharing the technology and dry goods of network and operation and maintenance every day. 

  •  Motto: Keep your head down and hurry on your way, be respectful

  • Personal homepage: Homepage of Netdou

Table of contents

 foreword

1. Commonly used commands (directory and file management)

1. View file content

 2. Statistical search file content

3. Backup and restore files (compress and decompress)

 2. vi and vim editing and use

3. Linux command practical experiment


 foreword

This chapter will share common Linux commands (directory and file management) vi and vim editing.


1. Commonly used commands (directory and file management)

1. View file content

View file content more less cat head tail

  •  more To view the content of large files, you can only use the space bar to turn the screen, and you can only turn the screen down
  •  less View the content of large files Use the arrow keys to scroll up and down the screen
  •  cat is suitable for viewing the content of small files and only displays one screen of content
  •  head Take the first few lines in the specified file head -n specify the file path
  •  tail go to the last few lines in the specified file tail -n specify the file path
  •  

  | Pipe character Function Connect two or more commands.


 2. Statistical search file content

Count the number of lines in the file, the number of bytes, the number of words: wc

  •      wc -l function to count the contents of the file
  •      wc -c counts the number of bytes in the file content
  •      wc -w counts the number of words in the file content

Retrieve file contents:

   grep option search condition target file

  •        -v means reverse selection
  •        ^# means start with #
  •        ^$ means empty line
  •        g$ means ending with g

3. Backup and restore files (compress and decompress)

   Compression and decompression (backup and restore)

    For files  gzip bzip ganzip bunzip 

    for folders

  •    Compression is equivalent to packing compression tar -zcvf
  •    Decompression is equivalent to unpacking tar -zxvf
  •     -z calls the gzip program for compression
  •     -c create .tar package
  •     -x unpack the .tar package
  •     -f means to use the archive file
  •     -v output verbose information
  •     -j calls the bzip2 program for compression or decompression                                                                        
  •     -C Specify the target folder to release to when decompressing


 2. vi and vim editing and use

vim and vi are linux text editors, vim is an upgraded version of vi

 Three major modes of vim editor: command line mode, edit mode, last line mode

  • Command line mode: The first mode that vim enters when opening a file can be realized  
  •       Copy yy delete dd paste p move dd + p undo u find "/find content" and other operations
  •       Jump n+gg    n indicates the number of lines
  • Edit mode: Enter the i key in the command line mode to enter the edit mode to edit the content
  • Last line mode: In edit mode, press esc key to return to command mode, enter shif + : to enter last line mode
  •       It can be realized Save w Exit q Force quit q! Save as w Specify the path   
  •       Open the specified file e specify the path r specify the path save and exit x  
  •       Replace Replacement range sub /old content/new content/g
  •       Show line number: set nu

  • 3. Linux command practical experiment


  • 7. Copy the /etc/passwd file to / and change the name to password
        cp /etc/passwd /password

    8. The use of vi (take /etc/passwd as an example)
         1, display line number
    2, jump to line 40
       (3) delete the first line
       (4) delete 3 lines at one time
       (5) copy 3 lines at one time, Paste at the end of the file.
       (6) Check the characters of all bins from top to bottom
       (7) Replace all bins in the entire document with 333
       (8) Replace 333 in lines 3 to 5 with 444
       (9) Save and exit.
       (10) Save /etc/passwd as /tmp/passwd
        (11) Add /etc/resolv.conf to /etc/passwd
       


     Creation is not easy, please pay attention, like, collect, thank you~   

Guess you like

Origin blog.csdn.net/yj11290301/article/details/129270347