1. The grep command:
    • Finding a string in a single file:
      • grep "literal_string" fileName
        • Example:grep "this" demo_file
    • Find strings in multiple files:
      • grep "string" fileNamePattern
        • Example:grep "this" demo_*
    • Case insensitive:
      • grep -i "literal_string" filename
        • Example:grep -i "this" demo_file
    • Regular expression lookup:
      • grep "REGEX" filename
        • Example:grep "lines.*empty" demo_file
    • Find a whole word, not a substring:
      • grep -w "literal_string" demo_file
        • Example:grep -w "is" demo_file
    • Find all files under the current file:
      • grep -r "literal_string"
        • Example:grep -r "is"
    • Number of matches counted:
      • grep -c "pattern" filename
        • Example:grep -c "is" demo_file
    • Display only matching filenames:
      • grep -l "pattern" filename
        • Example:grep -l "is" demo_file
    • Display the matching line number:
      • grep -n "pattern" filename
        • Example:grep -n "is" demo_file
  2. The find command:
    • Find at the specified path:
      • find pathName -name fileName
        • The samplefind / -name mysqld.log
    • Find in the specified path, case insensitive:
      • find pathName -iname fileName
        • The samplefind / -iname mysqld.log
    • Specify the depth of the search depth:
      • find pathName -mindepth mindepth -maxdepth maxdepth -name fileName
        • The samplefind / -mindepth 2 -maxdepth 3 -name mysqld.log
    • Specify the file type:
      • find pathName -name fileName -type typeName
        • The samplefind / -name test.txt -type -f
        • – the type:
          • B: Block device file
          • C: character device file
          • D: Directory file
          • F: Ordinary files
          • P: pipe file
          • L: Symbolic links
    • Specify file size:
      • find pathName -size fileSize
        • Find files larger than 100 M:find / -size +100M
        • Find files smaller than 100 M:find / -size -100M
    • Select * from inode;
      • find -inum inodeNumber
        • Example:find -inum 2165021
    • Files used or modified within the specified date range:
      • find / -name fileName -mtime n
        • Search for files whose modification time is more than 100 days from the current time:find / -mtime +100
        • -mtime indicates the modification time, and -atime indicates the access time
        • +n indicates that the number is exceeded. -n indicates that the number is not exceeded
    • After finding the file, execute the corresponding command:
      • find / -name fileName -exec command {} \;
        • File information is displayed after the file is found:find / -name test.txt -exec ls -l {} \;
    • Find the largest or smallest files:
      • Find the largest 5 files:find . -type f -exec ls -s {} \; | sort -n -r | head -5
      • Find the smallest 5 files:find . -type f -exec ls -s {} \; | sort -n | head -5
  3. The locate command:
    • Find a file:locate fileName
      • Example:locate *.doc

        Locate finds files in a database that has been created. Sometimes a file has changed, for example by deleting it, but locate still finds the file because the file database has not been updated. This parameter is required if the file database needs to be updatedupdatedbCommand.
  4. [1] : The Ultimate Tar Command Tutorial with 10 Practical Examples [2] : 15 Practical Linux Find Command Examples [3] : Linux from Beginner to Master (2nd edition)