The article directories

  • 1. Search for lookup classes
    • 1.1 the find command
    • 1.2 the locate command
    • 1.3 grep command and pipe symbol │

1. Search for lookup classes

1.1 the find command

  • The find command recursively traverses the subdirectories from the specified directory and displays the files or directories that meet the conditions on the terminal.
  • Basic syntax:Find [option]
  • Option to show

  • Examples of application
  1. Case 1: By filename: Search by name/homeHello. TXT file in the directory
find /home -name hello.txt
Copy the code
  1. Case 2: Find by Owner:/optIn the directory, the user name is nobody
find /opt -user nobody
Copy the code
  1. Example 3: Find files larger than 200M in Linux (+n greater than, -n less than, n equal to, k,M,G)
find / -size +200M
Copy the code

1.2 the locate command

  • The locate directive can quickly locate a file path. The Locate directive quickly locates a given file using the LOCATE database of all file names and paths established in the system. The Locate command does not need to traverse the entire file system, resulting in faster queries. To ensure the accuracy of query results, administrators must periodically update locate time
  • Basic syntax:Locate search file
  • Special instructions

    Because the LOCATE directive queries based on a database, it must be used before the first runupdatedbCommand to createlocateThe database.
  • Examples of application

    Case 1: Please uselocateCommand quick locationhello.txtThe directory where the file is located does not return data if it cannot be found
locate hell.txt
Copy the code
  • Add: which directive, you can see which directory an instruction is in, such as ls directive in which directorywhich Is

1.3 grep command and pipe symbol │

  • Grep filter to find, pipe character,”|“Indicates that the processing result of the previous command is transferred to the subsequent command.
  • The basic grammar
Grep [option] Find the content source fileCopy the code
  • Commonly used options

  • Examples of application
  1. Case 1: Pleasehello.txtFile, find”yes“, and displays the row

Method 1:

cat /home/hello.txt | grep -n "yes"
Copy the code

Method 2:

grep -n "yes" /home/hello.txt
Copy the code