The search commands under Linux are mainly found and grep, and the two are different:
The Find command is based on the properties of the file , such as file name, file size, owner, owning group, whether it is empty, access time, modification time, etc.
grep is a lookup based on the contents of the file, and each line of the file is matched in a given pattern (patter).
1.find Command Basic format:
Find path -name filename looks for a file named filename in the directory corresponding to path
eg
Find. -name AAA.C Find AAA.C in the current directory
Find/etc-name ' *srm* ' #使用通配符 * (0 or any number). Find files in the/etc directory that contain the string ' SRM ' in the file name
2.grep Find
File to search for a word, the command returns a line of text containing "parent-tags"
grep "Parent-tags" file_name
Find in multiple files:
grep "Match_pattern" File_1 file_2 file_3 ...
Mark Match color --color=auto options:
grep "Match_pattern" file_name --color=auto
Search with options:
grep "str"./-r-l
Options:
-ADo not omit binary data.
-A< show columns > displays the contents of the row, in addition to the row that conforms to the template style.
- bDisplays the line that matches the template style, and displays the contents before it.
- CCalculates the number of columns that conform to the template style.
-c< Display number of columns > or-< display columns >In addition to displaying the column that conforms to the template style, the content before the column is displayed.
-d< for action >You must use this parameter when you specify that you want to find a directory rather than a file, otherwise the grep command returns information and stops the action.
-e< template Style >Specifies a string as the template style for finding the contents of a file.
- eUsing the template style as an extended normal notation means using an extended regular expression that can be used.
-f< template File >Specifies the template file whose contents have one or more template styles that let grep find the contents of the file that match the template criteria, in the form of a template style for each column.
- FTreats the template style as a list of fixed strings.
- GUse the template style as a normal notation.
- HThe name of the file to which the column belongs is not marked until the column that conforms to the template style is displayed.
- HBefore displaying the column that conforms to the template style, indicate the file name of the column.
- I.Ignores the difference in case of characters.
- LLists file names that match the file contents to the specified template style.
- LLists file names for file contents that do not conform to the specified template style.
- NMark the column number before displaying the column that conforms to the template style.
- Qdoes not display any information.
-r/-rThe effect of this parameter is the same as specifying the "-D recurse" parameter.
- SNo error message is displayed.
- vReverse lookup.
-W Only columns that match the whole word are displayed.
- xDisplays only the columns that are eligible for all columns.
- yThe effect of this parameter is the same as "-I".
- oOnly the portion of the file that matches to is output.
Linux Find and grep