File directory class of Linux utility instruction

File directory class

  • pwd instruction

    pwd	(Function Description: displays the absolute path of the current working directory)
    
    • Case: displays the absolute path of the current working directory

      # pwd
      
  • ls instruction

    ls [ Options]	[Directory or file]
    
    -a : Displays all files and directories in the current directory, including hidden ones.
    -l : Display information as a list
    
    • Case: view all content information of the current directory

      #ls -l
      
      # ls -al
      
  • cd instruction

    cd	[parameter] (Function Description: switch to the specified directory)
    
    cd ~ perhaps cd : Go back to your home directory
    
    cd .. Return to the previous directory of the current directory
    
    • How to understand absolute path and relative path

      When the current working directory is / root, we want to enter / home

      1. Absolute path: / home starts from the root directory
      2. Absolute path:... / home locate the required directory from the current working directory
    • Case 1: use absolute path to switch to root directory

      cd	/root
      
    • Case 2: use relative path to / root directory

      Here, we need to know which directory the user directory is in before we can write this instruction. Suppose/usr/lib
      cd	../../root
      
    • Case 3: it means to return to the previous directory of the current directory

      cd ..
      
    • Case 4: home directory cd

      cd	~
      
  • mkdir Directive: used to create directories

    mkdir	[option]	Directory to create
    
    -p : Create multi-level directory
    
    • Case 1: create a directory / home/dog

      # mkdir /home/dog means to create a dog directory under the / home directory
      
    • Case 2: create multi-level directory / home/animal/tiger

      # mkdir -p /home/animal/tiger 
      If you want to create a multi-level directory at one time,close-p Parameters are enough
      
  • rmdir instruction: delete empty directory

    rmdir	[option]	Empty directory to delete
    
    • Case 1: delete a directory / home/dog

      # rmidr /home/dog
      # cd /home/
      # ls
      
    • Use details

      rmdir An empty directory is deleted. If there is content in the directory, it cannot be deleted
       Tip: if you need to delete a non empty directory, you need to use	rm -rf Directory to delete
      # Rmdir / home / dog rmdir cannot delete non empty directories
      # rm -rf /home/dog if you want to delete a non empty directory, you can use rm -rf directory
      
  • touch instruction: create an empty file

    touch File name
    
    • Case 1: create an empty file hello txt

      # touch hello .txt
      # ls
      #ls -l
      # touch ok1.txt ok2.txt
      # ls
      
  • cp instruction [important]: copy files to the specified directory

    cp [option] source dest
    
    -r : Copy entire folder recursively
    
    • Case 1: Add / home / AAA Txt copy to / home/bbb directory [copy a single file]

      # touch aaa.txt
      # ls
      # mkdir bbb
      # ls
      # cp aaa.txt bbb / add aaa.txt to the current directory Txt file is copied to the bbb directory of the current directory
      # cd bbb/
      # ls
      
    • Case 2: recursively copy the entire folder, for example: copy the entire directory of / home/test to the directory of / home/zwj

      # cp -r test/ zwj / be sure to pay attention to your current directory location, and then accurately locate the source directory and target directory
      # cd zwj/
      # ls
      # cd test/
      # ls
      # pwd
      
      To force overwriting without prompting:\cp
      # cp -r test/ zwj / when you find the same file in the target directory, you will be prompted whether to overwrite it
      # /cp -r test/ zwj / force to overwrite the original file without prompting
      
      You can call up the previously used instructions through the up and down arrow keys.
      
  • rm instruction: delete [delete] file or directory

    rm	[option]	File or directory to delete
    
    -r : Delete entire folder recursively
    -f :  Force deletion without prompting
    
    • Case 1: Add / home / AAA Txt delete

      # rm aaa.txt delete file
      
    • Case 2: recursively delete the entire folder

      # rm -rf bbb / delete directory
      
      • The method of forcibly deleting non prompt: just bring the - f parameter

        # rm -f okl.txt
        
  • mv instruction: move files and directories or rename

    mv	oldNameFile newNameFile	(Function Description: Rename) 
    mv /temp/movefile /targetFolder (Function Description: move files)
    
    • Case 1: Add / home / AAA Txt file renamed pig txt

      # mv aaa.txt pig.txt will AAA Txt renamed big txt
      
    • Case 2: Add / home / pig Txt file to / root directory

      # mv pig.txt /root / put the pig of the directory Txt to the root directory
      
  • cat instruction: view the contents of the file and open it in a read-only manner

    cat	[option] File to view
    
    -n : set number 
    
    • Case 1: the contents of the / etc / profile file and the line number is displayed

      # cat -n /etc/profile |more open the file with the cat command and display it in pages
      
      • cat can only browse files, but cannot modify files. In order to browse conveniently, it usually brings the pipeline command | more
      • cat file name | more [paging browsing]
  • more instruction

    • The more instruction is a text filter based on the VI editor, which displays the contents of the text file page by page in a full screen manner. Several shortcut keys are built into the more instruction

      more File to view
      
    • Case: using more to view files

      # more /etc/profile
      
    • Shortcut key

      Space keyRepresents turning down a page
      EnterRepresents turning down one line
      qThe representative leaves more immediately and no longer displays the contents of the file
      Ctrl+FScroll down one screen
      Ct+ BReturn to previous screen
      =Output the line number of the current line
      :fOutput file name and line number of the current line
  • less instruction

    • The less instruction is used to view the contents of files on separate screens. Its function is similar to that of the more instruction, but it is more powerful than the more instruction and supports various display terminals. When the less instruction displays the contents of a file, it does not load the whole file at once, but loads the contents according to the display needs. It has high efficiency for displaying large files.
      less File to view
      
    • Case: use less to view a large file / opt / Jin Yong - carving hero biography TXT fine correction version txt

      # less Jinyong - Shooting Heroes TXT fine edition txt
      
    • Shortcut key

      Blank keyTurn down a page
      [pagedown]Turn down a page
      [pageup]Turn up a page
      /StringSearch down [string] function: N: search down N: search up
      ? stringSearch up [string] function: N: search up N: search down
      qLeave the less program
  • >Instructions and > > instructions

    • Output redirection: the contents of the original file will be overwritten. Instead of overwriting the contents of the original file, it will be appended to the end of the file

       ls -l >file
      
    • Function Description: write the contents of the list into the file a.txt (overwrite)

      # ls -l > a.txt
      # more a.txt
      
    • LS - Al > > file (function description: the contents of the list are appended to the end of the file aa.txt)

      # ls -l > > b.txt append the contents displayed by ls -l to the following folder
      
    • cat file 1 > file 2 (function description: overwrite the contents of file 1 to file 2)

      # cat /etc/profile > c.txt
      
    • echo "content" > > file

      1. Case 1: write the file list in the / home directory to / home / info Txt

        # ls -l /home/ > /home/info.txt
        # more info.txt
        
      2. Case 2: append the current calendar information to the / home/mycal file [prompt cal]

        # cal >> /home/mycal
        
  • echo instruction: output content to console

    echo	[option]	[Output content]
    
    • Case: use echo instruction to output environment variables and current environment path.

      # echo $PATH output $PATH environment variable
      
    • Case: use echo command to output hello,world!

    • Case: use echo instruction to output environment variables and current environment path.

  • head instruction

    • Head is used to display the first part of the file. By default, the head instruction displays the first 10 lines of the file.

      head  file	(Function Description: view the 10 lines of the file header)
      head -n 5 file	(Function Description: view the contents of 5 lines in the file header. 5 can be any number of lines)
      
    • Case: check the first five lines of code in / etc/profile

      # head -n 5/etc/profile
      
  • tail instruction

    • Tail is used to output the contents at the end of the file. By default, the tail instruction displays the last 10 lines of the file.

      tail  file	(Function Description: within 10 lines after viewing the file)
      tail -n5 File (function description: view the contents of the last 5 lines of the file, and 5 can be any number of lines)
      tail          (Function Description: track all updates of the document in real time (often used in work)
      
    • Case 1: check the last 5 lines of code in / etc/profile

      # tail -n 5 /etc/profile
      
    • Case 2: real time monitoring mydate Txt to see if you can see the real-time additional date when the file changes

      # tail -f mydate.txt real time monitoring mydate Txt there is no change, if there is a change, if there is a change, you will see
      
  • ln instruction

    • Soft links, also known as symbolic links, are similar to shortcuts in windows. They mainly store the paths linking other files

      ln -s [Original file or directory] [Soft link name] (Function Description: create a soft link to the original file)
      
    • Case 1: create a soft connection linkToRoot under the / home directory and connect to the / root directory

      # ln -s /root linkToRoot
      root Files in the original directory 
      Root Soft link file
      # rm -rf linkToRoot
       When deleting a soft connection file,Don't bring/ Otherwise prompt,Resource busy
       When we use pwd When viewing the directory, you still see the directory where the soft link is located.
      
  • History command: view the history command that has been executed, or execute the history command

    history	(Function Description: view the history commands that have been executed)
    
    • Case 1: display all historical commands

      # history
      
    • Case 2: display 10 recently used instructions

      # history 10
      
    • Case 3: execute the instruction with history number 5

      # ! 178 execute instruction number 178
      

Keywords: Linux Operation & Maintenance server

Added by danesc on Wed, 02 Feb 2022 15:52:58 +0200