Linux Chapter 3: File and Directory Related Instructions (must be mastered)

Summary of file and directory related instructions

1.1 pwd command (display path)

      pwd : Display the absolute path of the current working directory.
      Mainly used for configuration files or execution files that need to use the absolute path, you can use pwd to obtain and copy

1.2 ls command (display file)

      ls [Parameter] [Directory or File] : Display the files under this path.

      Parameter introduction

       -a: Display all files and directories in the current directory, including hidden (files beginning with .).
       -l: Display information in a list, vertically.
       -h: Display file size, with kmg as the unit of measurement.

       Can be followed by multiple parameters, can be abbreviated as ll or ls

1.3 cd command (switch working path)

       cd [parameter] [switch to the specified directory]

       Special parameters :

       cd… return to the previous directory
       cd without parameters, return to the home directory, for example, the root user will return to /root/

1.4 mkdir command (make directory)

  • mkdir [options] [directory to be created]
  • -p : create a multi-level directory

1.5 rmdir command (remove directory)

  • rmdir [options] [empty directory to be deleted] : There are files in the directory that cannot be deleted.
  • Generally use rm more

1.6 touch command (create file)

  • Touch creates a new file and can also change the modification time of the file (if the file exists).
  • Usage : touch file name

1.7 cp command (copy files)

  • cp [options] [source file] [destination file]
  • -r: Copy the entire folder recursively.

1.8 rm command (deleted)

  • Remove file or directory
  • rm -rf file or directory (mandatory cascading deletion)
           -r: means recursive deletion, that is, delete all files and subdirectories in the directory.
           -f: Means for forced deletion, that is, no inquiry is required.

1.9 mv command (moving files or directories)

  • Move files and directories or rename
  • mv [moving file] [moving to directory]
  • If you move to the directory and move the file in the same directory, it means to modify the name

1.10 cat command (view file content)

  • cat [options] [file] : Only browse files and load them at one time.
  • -n : display the line number
           if the reading line by line, enter the enter
           page press the spacebar
           if you need to exit press q
          general practice to use more processing pipeline |. eg: cat a.txt | more

1.11 more command (view file content)

  • more directive is a compiler-based vi text filter , which, by way of full screen by page displays the contents of a text file.

  •        The shortcut keys for the more file are the same as cat, and the following shortcut keys
           Ctrl + F : scroll down one screen
           Ctrl + B : scroll up one screen
           = : output the line number of the current line
           : f : output the file name and line number

1.12 less command (view file content)

  • The less command is used to view the contents of large files on a split screen , which is more powerful than more. Supports various display terminals. Less does not display the entire file after loading it, but loads the content as needed, which is more efficient for viewing large files.
  • less file
           space key : scroll down a page
           [pagedown] : computer key, scroll down a page
           [pageup] : computer key, scroll up a page
           /string : scroll down to find a string, press n to find down, Press N to search up
           ? String : Scroll up to find a string, press n to search down, press N to search up
           q : leave

1.13 echo command (output to the console)

  • echo [options] [output content]
  • eg : output JAVA_HOME environment variable
  • echo $JAVA_HOME
  • Supplement : Enter the env command to view all environment variables of the system

1.14 head command (display the beginning of the file)

  • head is used to display the content at the beginning of the file, the default is the first ten lines of the file
  • head [options] [option parameters] [file]
           head -n 5 file : view the first 5 lines

1.15 tail command (display the contents of the end of the file)

  • tail is used to output the tail content of the file, by default it is the last ten lines
  • tail [option] [option parameter] [file]
           tail -n 8 file : view the last 8 lines of the file
           tail -f file : monitor the update of the file in real time
           Ctrl + S : pause monitoring
           Ctrl + Q : continue monitoring
           Ctrl + C : terminate monitor

1.16 >> and> instructions (redirect and append)

  • > Redirection, >> Append
           ls -l> File : write the contents of the list to the file (overwrite)
           ls -al >> File : write the contents of the list to the file (append)
           cat file 1> file 2 : Overwrite the content of file 1 to file 2
           echo "content" >> File : add the content to the file

1.17 ln instruction (link)

  • Soft links are also called symbolic links, similar to shortcuts in Windows, which mainly store the path to link other files
  • ln -s [source file or directory] [soft link name] : create a soft link for the source file and
           delete the soft link rm -rf soft link name

1.18 scp instruction (copy between linux)

      The linux scp command is used to copy files and directories between linux. scp is the abbreviation of secure cp, scp is a secure remote file copy command for ssh login under linux system, which is encrypted.

  • 语法: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
    [-l limit] [-o ssh_option] [-P port] [-S program]
    [[user@]host1:]file1 […] [[user@]host2:]file2
  • Common syntax: scp -r source directory root@host1: target directory
          

1.19 history command (historical command)

  • To view the historical commands that have been executed, you can also execute
           history [n] : display the most recently used n commands, if you do not add a number, it will display all of them by default
           ! n : execute the command with history number n

Thank you all for reading. Due to the limited ability of the editor, please contact me if you have any objections to the compilation. Please contact me email: [email protected], or directly comment and add a private message. I don’t read it anyway.

Guess you like

Origin blog.csdn.net/qq_44112474/article/details/103338851