The powerful grep command explains the grep command on the internet. it basically translates man commands. to tell the truth, forget it after reading it! I personally think that the best way to learn commands is to simulate the real environment, write some combinations of commands that may be used, and then digest them slowly. at least I am...
The powerful grep command explains the grep command on the internet. it basically translates man commands. to tell the truth, forget it after reading it! I personally think that the best way to learn commands is to simulate the real environment, write some combinations of commands that may be used, and then digest them slowly. at least I did. In the beginning, it was basically a dead log, and then gradually expanded the field of vision. after a long time, the accumulation would be much more. Now, go to the topic and talk about the awesome grep command. Www.2cto.com grep is the abbreviation of general regular expression parser. we can simply think of it as a search command in linux. Next, let's look at the example: 1. search for a specified string in a file in the/etc/passwd file. search for the string guolei: 1 grep 'guolei'/etc/passwd. Note that the quotation marks of guolei can be omitted, however, if the search string contains spaces or you use regular expressions, you need to add them. 2. search for a specified string in multiple files in the current directory and search for a file containing the string guolei: 1 grep-r guolei * Note:-r is the abbreviation of recursive, indicating recursive search. In the current directory. in the java file, search for a file containing the string guolei: 1 grep-r guolei *. java sometimes has many search results. we can use the less command to display the results: 1 grep-r guolei *. java | less or there are many search results. we only need to list the file name: 1 grep-rl guolei *. java also has a common requirement. we often want to find a file containing a specified string in a directory. Note that the above command cannot be searched recursively. For example, we want to Recursively search for all objects in the current directory. the java file contains the string guolei: 1 find. -type f-name *. java-exec grep-il guolei {}\; 3. case-insensitive when searching guolei, case-insensitive: 1 grep-ri guolei * Note:-I is the abbreviation of Ignore case, indicating case-insensitive. 4. the row numbers listed in the search results are listed in the search results. The row numbers at the position where the string appears are listed: 1 grep-rn guolei *. java note-n is the abbreviation of number, indicating the meaning of a row number. 5. in actual development of reverse search, there is another common situation. we need to search for a file that does not contain a string in a directory: 1 grep-riv guolei * | less note: -v is the abbreviation of reverse, indicating reverse. The preceding example shows how to search for files that do not contain guolei in the current directory. 6. using grep in pipelines we often use grep in pipeline commands, which is the most common. For example, we need to search for the mysql process in the current system: 1 ps-ef | grep mysql or list the files ending with html in the current directory: 1ls | grep 'HTML $'
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service