The $ grep ' test ' d* shows all the lines in the file that begin with D that contain test. The $ grep ' test ' AA bb cc Displays the line in the aa,bb,cc file that matches the test. The $ grep ' [a-z]\{5\} ' AA displays all lines that contain a string of at least 5 consecutive lowercase characters per string. $ grep ' w\ (es\) T.*\1′AA if West is matched, es is stored in memory, labeled 1, and then searched for any character (. *) followed by another ES (\1), which is found to display the line. If you use Egrep or GREP-E, you do not have to escape the "\" number, directly written as ' W (es) t.*\1′.
No matter what the current path is, if you want to find the file name in your root $home that matches *.txt, use ~ as the ' pathname ' parameter, and the tilde ~ represents your $home directory.
$ find ~-name "*.txt"-print
To find all the ' *.txt ' files in the current directory and subdirectories, you can use:
$ find. -name "*.txt"-print
You want the current directory and subdirectories to find file names that begin with an uppercase letter, which can be used:
$ find. -name "[a-z]*"-print
To find files with the file name beginning with host in the/etc directory, you can use:
$ find/etc-name "host*"-print
To find files in the $home directory, you can use:
$ find ~-name "*"-print or find. -print
To get the system running at a high load, start looking for all the files from the root directory:
$ find/-name "*"-print
If you want to find the file name in the current directory with two lowercase letters, followed by two digits, and finally the. txt file, the following command will be able to return files such as the file named Ax37.txt:
$find. -name "[A-z][a-z][0-9][0-9].txt"-print
Example of the Find command;
1. Find all files under the current user's home directory:
Here are two ways to use
$ find $HOME-print$ Find ~-print
2, let the current directory of the file owner has read, write permissions, and the file belongs to the group of users and other users have Read permission files;
$ find. -type f-perm 644-exec ls-l { } \;
3, in order to find all the files in the system file length of 0 ordinary files, and list their full path;
$ find/-type f-size 0-exec ls-l { } \;
4. Look for common files in the/var/logs directory that were changed before 7th, and ask them before deleting them;
$ find/var/logs-type f-mtime +7-ok rm { } \;
5, in order to find all the files belonging to the root group in the system;
$find. -group root-exec ls-l { } \;
6. The Find command will delete the Admin.log file that contains the digital suffix since the access time in the directory was 7th.
This command checks only three digits, so the suffix of the corresponding file should not exceed 999. Build several admin.log* files before using this command
$ find. -name "admin.log[0-9][0-9][0-9]"-atime-7 -ok rm { } \;
7, in order to find all the directories in the current file system and sorting;
$ find. -type D | Sort
Like SED, pattern is a regular expression, and actions are a series of actions. The AWK program reads the pending file one line at a time, if a line matches the pattern, or if the condition condition is met, the actions are performed if an awk command has only the Actions section, and the actions are applied to each row of the file to be processed. For example, the contents of a file testfile indicate the stock quantity of a store:
ProductA 30ProductB 76ProductC 55
Print the second column of each row:
$ Awk ' {print $;} ' testfile307655
The automatic variable, $ $, is the first column, the second column, and so on, similar to the location parameter of the shell script, and $ A represents the entire current row. For example, if the stock of a product is below 75, an order is required at the end of the line:
$ Awk ' $2<75 {printf "%s\t%s\n", $ A, "REORDER";} $2>=75 {print $;} ' testfileproducta reorderproductb< C8/>76PRODUCTC REORDER
Linux grep sed awk