Study Notes(6)

1.fgrep does not support regular expression search

2.grep abc accepts standard input, indicating that it can accept pipes to process the output

3.grep [file] file is optional, no file means accept standard input

  Usage: grep [OPTION]... PATTERN [FILE]...

  Usage: cat [OPTION]... [FILE]...

4.grep "$USER" /etc/passwd grep can also use variables as patterns to find

5.grep `whoami` /etc/passwd    grep can also use command substitution as a pattern to find

6.cat -n /etc/passwd | grep root Perform grep search through the output of cat -n with line number content

7. Whether grep -q contains judgment -q option is silent output, nothing is output, you can use echo $? to judge whether the command is executed successfully

8.nmap -v -sP 172.20.20.0/24 Scan network segment for surviving hosts

9.grep -e 'cat' -e 'bash' /etc/passwd Multiple or relational patterns can be connected using -e

10. The words in grep are composed of numbers, underscores, and letters, not separated by spaces

11. The matching characters in grep -f file are or are similar to -e

12. Wildcard (pattern) is the content that matches the file name. There will be pattern support in the use of some commands. Regular expressions process specific strings in the text (REGEXP)

13. Regular expression software module (PCRE: Perl Compatible Regular Expressions), you need to install this package if you rely on regular expressions

14. A single Chinese character is also counted as a character, so it can be matched by .

15.ls | grep ... The output of the ls pipeline is the content, not the file name, so grep can be used to process it

16. echo abb | grep "ax*b" matches, because ab before abc matches a*b

   echo abab |grep -E "(ab)*" matches ab combination zero or more times

17.grep -o only displays the matching content (commonly used), often used to judge the value

   df |grep '/dev/sda' |grep -o " [[:digit:]]\{1,3\}%" | grep -o "[0-9]\+"|sort -nr |head -1

18. The default greedy match echo abccdd |grep "a[az]c" matches the result abcc

19.\? Occurs 0 or 1 times, use egrep (grep -E option can use ? directly without escaping \)

20. Putting it in square brackets is just. The character is not a single character that needs to be matched, and no \ line translation is required, such as: echo "1." |grep "[az.]\+" match

21.Ctrl + k delete from the cursor to the end of the command line

22.ifconfig ens33|grep -o  "[0-9]\{1,3\}[.][0-9]\{1,3\}[.][0-9]\{1,3\}[.][0-9]\{1,3\}"  |head -1

23. The pattern of grep should be quoted, otherwise it is easy to have problems

24.grep -v "^[[:space:]]*$" f1 [[:space:]] means there is a tab key or a space

25.grep "root\>" /etc/passwd    anchor word ending

26.grep "\broot\b" /etc/passwd to anchor the whole word (same as grep -w to find words)

27.grep wangwangwang |grep "\(wang\)\{3\}" to match the whole, be careful to use translation characters

28. Back reference grep wangwangwangxxxxwangwangwang |grep "\(wang\)\{3\}.*\1

\1 matches the result, not the pattern itself

29.grep "^bash.*bash$" /etc/passwd Find out the lines that start with bash and end with bash

30.grep '^\(.*\):.*/\1$' /etc/passwd Find lines with the same beginning and end

31.grep "^\(a\|b\).*" /etc/passwd Find out the lines starting with a or starting with b

32.echo axy |grep "\(a\|b\)xy" Find out the line with axy or bxy

33.grep -o "[0-9]\+" /etc/redhat-release |head -n1 Find out the major version number in the text

34. The extended regular expression removes the escape character \ in the regular expression, except that the word anchors are /< and /> such as egrep (grep -E)

35.grep -Ewo "[0-9]{2,3}" /etc/passwd Find out two to three digits in the file

36.grep -E = egrep

37.echo "/etc/rc.d/init.d/functions" |grep -Eo "[^/]*/?$" Take the base name of the output

38.vim -d file1 file2 -d option is used to compare the differences between two files

39. vi editor I key jumps directly to the beginning of the line, A jumps directly to the end of the line

40.vi save as: w another file

41. ! means that the forced q key can exit directly. After modifying the file, you need q!

42.r file reads the file, you can read the command output with r!command

43.vi +/pattern file pattern is a regular expression

44.%s/\(haha\)/\1er/ Only basic regular expressions are supported in the vim editor

45.%s/^UUID/#&/

46. ​​ctrl + r cancel undo

47.:set ff=unix Modify the content of the window file format to the format of the unix file

48.vimtutor View vim editor help

48.cat hellp.sh | bash can be used to call remotely

49.curl http://192.168.30.128/hello.sh |bash remote call execution

50.ls use the -d option without specifying a file folder to display the file or directory of the current path without recursive directory

51.vim register 3"ayy means copy three lines to the t register  

              "ap means to paste the contents of the t register, there can be up to 26 registers, namely az

52. Use ctrl + r in the vim editor to redo the last undo change, use U to undo all the changes in this line after the cursor falls on this line

53. The selection replacement used in the vim editor uses basic regular expressions, so when using the number of matches? and + signs, you need to use escape characters, that is, \? and \+


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324604362&siteId=291194637