find files under [reprint] linux command grep to find content File Finder find file under linux command grep command to find the contents of the file search command

find files under linux find command with the contents of the file search command grep

 
https://www.cnblogs.com/shileima/p/8431393.html

 

  When using linux, often you need to find files. Find command which mainly find and grep. There are two command areas.

  The difference between : (1) find command is based on the attributes of the file to find, such as file name, file size, owner, owning group, is empty, access time, modification time. 

               (2) grep is based on the content of the file search, each line of the file will look to match the given pattern (patter).

  A command .find

    The basic format: the Find expression The path

    1. Find by file name

    (1) find / -name httpd.conf # httpd.conf find files in the root directory, it represents the entire hard drive to find
    (2) find / etc -name httpd.conf # in the / etc directory file httpd.conf
    (3) find / etc -name '* srm * ' # * using wildcards (0 or any number). A lookup in the / etc directory file name contains the string 'srm' document
    (4) find. -Name 'srm *' # denote find the beginning of the file name in the current directory is the string 'srm' files

    2. Find the file in accordance with characteristics     

    (1) find / -amin -10 # find access system files in the last 10 minutes (Access Time)
    (2) Find / -atime -2 # Find access the last 48 hours in a file system
    (3) find / - in the system to find empty # empty file or folder
    (4) find / -group cat # lookup belonging to the group in the file system of cat
    (5) find / -mmin -5 # lookup system in the last five minutes modified files (modify Time)
    (. 6) Find / -mtime -1 # search the last 24 hours in the modified file system
    (7) find / -user fred # fred lookup belonging to this file in the user's system
    ( 8) find / -size + 10000c # to find out a file larger than 10,000,000 bytes (c: bytes, w: double word, K: KB, M: MB, G: GB)
    (. 9) Find / -size -1000k # Find out the file of less than 1000KB

    3. Find a way to find files using a hybrid

    The parameters are:! , -And (-a), - or (-o).

    (1) find / tmp -size + 10000c -and -mtime +2 # lookup in / tmp is larger than 10,000 bytes and modifications within the last 2 minutes of the file
         (2) find / -user fred -or -user george # Find the user in the / directory is fred george file or files
         (3) find / tmp! -user panda # find all files that do not belong panda users in the / tmp directory
        

  Two, grep command

     The basic format: the Find expression The

     1. The main parameters

    [options] The main parameters:
    -C: Only output count of matching lines.
    -I: case-insensitive
    -h: do not display the file name when querying multiple files.
    -L: only the output file name contains characters match the query multiple files.
    -N: display matching lines and line number.
    -S: do not display an error message does not exist or no match text.
    -V: Displays all lines matching text.

    The main parameters of a regular expression pattern:
    \: ignore the original meaning of the regular expression special characters.
    ^: Match the regular expression of the start line.
    $: The end of the line matches the regular expression.
    \ <: Beginning match the regular expression.
    \>: The line to match the regular expression ends.
    []: A single character, such as [A] i.e. A compliance.
    [-]: range, such as [AZ], i.e. A, B, C until Z meet the requirements.
    .: All single character.
    *: There are characters in length can be zero.

    2. Examples  

  (1) grep 'test' d * # display all lines beginning of the document d contains the test in
  (2) grep 'test' aa bb cc # shown in aa, bb, line cc file contains test in
  (3) grep '[az] \ {5 \ }' aa # all display lines of strings to contain at least five consecutive lowercase string
  (4) grep magic / usr / src # display the / usr / src directory files (sub-folders) line contains the magic
  (5) grep -r magic / usr / src # display the / usr / src directory file (including subdirectories) comprising rows magic

  (6) grep -w pattern files: matching only whole words a, instead of the string portion (such as matching 'magic', rather than 'magical'),

  When using linux, often you need to find files. Find command which mainly find and grep. There are two command areas.

  The difference between : (1) find command is based on the attributes of the file to find, such as file name, file size, owner, owning group, is empty, access time, modification time. 

               (2) grep is based on the content of the file search, each line of the file will look to match the given pattern (patter).

  A command .find

    The basic format: the Find expression The path

    1. Find by file name

    (1) find / -name httpd.conf # httpd.conf find files in the root directory, it represents the entire hard drive to find
    (2) find / etc -name httpd.conf # in the / etc directory file httpd.conf
    (3) find / etc -name '* srm * ' # * using wildcards (0 or any number). A lookup in the / etc directory file name contains the string 'srm' document
    (4) find. -Name 'srm *' # denote find the beginning of the file name in the current directory is the string 'srm' files

    2. Find the file in accordance with characteristics     

    (1) find / -amin -10 # find access system files in the last 10 minutes (Access Time)
    (2) Find / -atime -2 # Find access the last 48 hours in a file system
    (3) find / - in the system to find empty # empty file or folder
    (4) find / -group cat # lookup belonging to the group in the file system of cat
    (5) find / -mmin -5 # lookup system in the last five minutes modified files (modify Time)
    (. 6) Find / -mtime -1 # search the last 24 hours in the modified file system
    (7) find / -user fred # fred lookup belonging to this file in the user's system
    ( 8) find / -size + 10000c # to find out a file larger than 10,000,000 bytes (c: bytes, w: double word, K: KB, M: MB, G: GB)
    (. 9) Find / -size -1000k # Find out the file of less than 1000KB

    3. Find a way to find files using a hybrid

    The parameters are:! , -And (-a), - or (-o).

    (1) find / tmp -size + 10000c -and -mtime +2 # lookup in / tmp is larger than 10,000 bytes and modifications within the last 2 minutes of the file
         (2) find / -user fred -or -user george # Find the user in the / directory is fred george file or files
         (3) find / tmp! -user panda # find all files that do not belong panda users in the / tmp directory
        

  Two, grep command

     The basic format: the Find expression The

     1. The main parameters

    [options] The main parameters:
    -C: Only output count of matching lines.
    -I: case-insensitive
    -h: do not display the file name when querying multiple files.
    -L: only the output file name contains characters match the query multiple files.
    -N: display matching lines and line number.
    -S: do not display an error message does not exist or no match text.
    -V: Displays all lines matching text.

    The main parameters of a regular expression pattern:
    \: ignore the original meaning of the regular expression special characters.
    ^: Match the regular expression of the start line.
    $: The end of the line matches the regular expression.
    \ <: Beginning match the regular expression.
    \>: The line to match the regular expression ends.
    []: A single character, such as [A] i.e. A compliance.
    [-]: range, such as [AZ], i.e. A, B, C until Z meet the requirements.
    .: All single character.
    *: There are characters in length can be zero.

    2. Examples  

  (1) grep 'test' d * # display all lines beginning of the document d contains the test in
  (2) grep 'test' aa bb cc # shown in aa, bb, line cc file contains test in
  (3) grep '[az] \ {5 \ }' aa # all display lines of strings to contain at least five consecutive lowercase string
  (4) grep magic / usr / src # display the / usr / src directory files (sub-folders) line contains the magic
  (5) grep -r magic / usr / src # display the / usr / src directory file (including subdirectories) comprising rows magic

  (6) grep -w pattern files: matching only whole words a, instead of the string portion (such as matching 'magic', rather than 'magical'),

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11512172.html