In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use grep commonly used Linux commands, Xiaobian feels quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
The grep command is used to find strings that match the criteria in a file. The grep command is used to find files whose contents contain the specified template style. If the contents of a file are found to match the specified template style, the grep command will display the column containing the template style by default.
syntax grep [-abcEFGhHilLnqrsvVwxy][-A][-B][-C][-d][-e][--help][template style][file or directory...] Parameters:
-a or-text : Do not ignore binary data.
-A or-after-context= : Displays the content after that row, except for the column that matches the template style.
-b or-byte-offset : Mark the number of the first character of the line before displaying the line that matches the style.
-B or-before-context= : Display the content before the line except for the line that matches the style.
-c or-count : Counts the number of columns that match the style.
-C or-context= or- : Displays the line before and after the line except for the line that matches the style.
-d or-directories= : This parameter must be used when specifying directories rather than files, otherwise the grep directive returns information and stops the action.
-e or-regexp= : Specifies a string as a style to find the contents of a file.
-E or-extended-regexp : Use regular expressions whose style is extended.
-f or-file= : Specifies a rule file whose contents contain one or more rule styles, allowing grep to find file contents that match the rule criteria, formatted as one rule style per line.
-F or-fixed-regexp : treats styles as lists of fixed strings.
-G or-basic-regexp : Use styles as if they were normal notation.
-h or-no-filename : Does not indicate the file name to which the line belongs until the line that matches the style is displayed.
-H or-with-filename : Indicates the file name to which the line belongs before displaying the line that matches the style.
-i or-ignore-case : Ignore case differences.
-l or-file-with-matches : Lists file names whose content matches the specified style.
-L or-files-without-match : Lists file names whose content does not conform to the specified style.
-n or-line-number : Mark the column number of the row before displaying the row that matches the style.
-o or-only-matching : Show only matching PATTERN parts.
-q or-quiet or-silent : No information is displayed.
-r or-recurrent: This parameter has the same effect as specifying the "-d recurrent" parameter.
-s or-no-messages : No error messages are displayed.
-v or-invert-match : Displays all lines that do not contain matching text.
-V or-version : Displays version information.
-w or-word-regexp : Displays only columns that match all words.
-x-line-regexp : Show only columns that match all columns.
-y : This parameter has the same effect as specifying the "-i" parameter.
Example 1: In the current directory, find the file containing the test string in the file with the suffix file, and print out the line of the string. At this point, you can use the following command:
grep test *file results are as follows:
$ grep test * #Find files prefixed with "test" Files containing the string "test" testfile1:This a Linux testfile! #List the lines in testfile1 that contain the test character testfile_2:This is a linux testfile! #List lines in testfile_2 file containing test character testfile_2:Linux test #List the lines in the testfile_2 file that contain the test character. 2. Find files that match the criteria recursively. For example, find all files in the specified directory/etc/acpi and its subdirectories (if any) that contain the string "update" and print out the contents of the line where the string is located, using the command:
grep -r update /etc/acpi outputs the following:
$ grep -r update /etc/acpi #Find "etc/acpi" recursively #Files containing "update" /etc/acpi/ac.d/85-anacron.sh:# (Things like the slocate updatedb cause a lot of IO.) Rather than /etc/acpi/resume.d/85-anacron.sh:# (Things like the slocate updatedb cause a lot of IO.) Rather than /etc/acpi/events/thinkpad-cmos:action=/usr/sbin/thinkpad-keys--update The previous examples are to find and print out the qualified lines, and the contents of the unqualified lines can be printed through the "-v" parameter.
Find the line that does not contain test in the file name containing test. In this case, the command used is:
grep -v test *test* results are as follows:
$ grep-v test* #Find lines that do not contain test in files with test in their names testfile1:helLinux! testfile1:Linis a free Unix-type operating system. testfile1:Lin testfile_1:HELLO LINUX! testfile_1:LINUX IS A FREE UNIX-TYPE OPTERATING SYSTEM. testfile_1:THIS IS A LINUX TESTFILE! testfile_2:HELLO LINUX! testfile_2:Linux is a free unix-type inverting system. About "Linux common command grep how to use" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.