Find command:
F I n d is a very effective tool that can traverse the current directory or even the entire file system to find some files or directories,
The general format is: Find pathname-options [-print-Exec-OK].
Find Command Options
-Name: searches for files by file name.
-Perm searches for files based on the file permissions.
-Prune can use this option to make the f I n d command not be found in the currently specified directory. If the-d e p t h option is used at the same time, the-P r u n e option is ignored by the f I n d command.
-The user searches for files based on the file owner.
-The group searches for files based on the group to which the files belong.
-Mtime-N + N: Find the file based on the file change time.-N indicates that the file change time is earlier than N days, and + N indicates that the file change time is earlier than N days.
-Type: search for a certain type of files, such:
B-block device files.
D-directory.
C-character device file.
P-MPs queue file.
L-Symbolic Link file.
F-common file.
Ex: [spsn @ localhost tan_c] $ find/etc-type D @: Find the directory in/etc
[Spsn @ localhost tan_c] $ find.-Type F @: find common files in the current directory
[Spsn @ localhost tan_c] $ find.-Name "*. c" @: Find the file name ending with. C in the current directory
[Spsn @ localhost tan_c] $ find.-mtime-5 @: searches for files in the current directory whose modification time is within five days
Grep command
. G r e p (Global Regular Expression version) allows Pattern searches for text files. If the matching mode is found, g r e p prints all rows containing the mode. G r e p supports basic positive
The expression also supports its extension set. G r e p has three types of Deformation:
G r e p: Standard g r e p command. This section focuses on this format in most sections.
E g r e p: Extended g r e p. It supports basic and extended regular expressions, but does not support applications in the \ q mode range, some of the more standardized models corresponding to them will not be discussed here.
F g r e p: Fast g r e p. You can search for strings instead of a single mode. Do not misunderstand the word f a s t. In fact, it is equivalent to g r e p.
The general format of g r e p is grep [Option] basic regular expression [file]. Here the basic regular expression can be a string.
Grep options
Common g r e p options include:
-C only outputs the Count of matched rows.
-I is case insensitive (only applicable to single characters ).
-H: When querying multiple files, the file name is not displayed.
-L only names containing matching characters are output when multiple files are queried.
-N: the matching row and row number are displayed.
-S does not display the error message that does not exist or does not match the text.
-V: displays all rows that do not contain matched text.
Exec:
[Spsn @ localhost tan_c] $ grep "Main" * @ search for the word "Main" in all files in the current directory"
[Spsn @ localhost tan_c] $ grep "printf" sum. c @ search for the string "printf" in the sum. c file in the current directory"
[Spsn @ localhost tan_c] $ grep-c "printf" letter. c @: display the number of rows containing the string "printf"
In several examples, the pipeline command, namely the symbol |, is used to use the output result of the command on its left as the input of the command on its right.
[Spsn @ localhost test] $ LS-L | grep '^ d' @ query the directory in the current directory list
G r e p is not only applied to files, but also to strings. Therefore, use the E c h o string command, and then use the pipeline to input the g r e p command.
[Spsn @ localhost test] $ STR = "Mary Joe Peter Paine"
[Spsn @ localhost test] $ echo $ STR | grep "Mary"