Special Symbols and Regular Expressions in Linux

Time:2019-10-12

Chapter 1 Special Symbols of Linux

1.1 wildcard * {}

1.1.1 meaning

Easy to find file wildcards are used to find file names.

1.1.2  *

Find the file ending with. sh by using the find command, and replace the file name with *.


find /oldboy -type f -name "*.sh" -mtime +7 -size +100k -size -10M

Find a file name that contains Oldboy bytes.


[[email protected] 20170118]# find -type f -name "*oldboy*"
[[email protected] 20170118]# ls -l *oldboy*

1.1.3  {}

{} Used to generate sequences


[[email protected] 20170118]# echo oldboy{1..3}.txt
oldboy1.txt oldboy2.txt oldboy3.txt
[[email protected] 20170118]# echo {a,c,d,f}

a c d f

Echo {a.z} {A.Z} needs a space between them to represent two unrelated sequences


[[email protected] 20170118]# echo {a..z} {A..Z}

a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Generate by regular sequence {start,… end,… interval}


[[email protected] ~]# echo {1..10..3}

1 4 7 10

Use when backing up a file


[[email protected] ~]# cp oldboy.txt{,.bak}
[[email protected] ~]# ll oldboy*
-rw-r--r-- 3 root root 241 Aug 30 11:40 oldboy.txt
-rw-r--r-- 1 root root 241 Aug 31 09:38 oldboy.txt.bak

1.2 Special Symbols

1.2.1 special symbols

> Standard output redirection, first empty the content, and then put something else into the file

Standard Addition Oriented to Documentation

Standard Input xargs

Additional input: cat >/oldboy.txt

Hidden files under the current directory / Linux

… current user’s previous directory

~ Current user’s home directory

/ Separation Symbol of Root Path

\ Temporarily cancel aliases

Pipeline

!

1) Force in VIM

2) Take anti-find awk

3) Represents using historical commands with commands you have used

! You can see the history command

       !ls   ===== history |grep ls


[[email protected] ~]# history

Annotation

Take out the contents of the variable

&& And the previous command runs successfully, then the next command runs


  ifdown eth0 && ifup eth0

Separate multiple commands and place multiple commands on the same line.


ls; pwd; hostname

1.2.2 single quotation mark, double quotation mark and no quotation mark

‘ ‘

What to eat and vomit


[[email protected] ~]# echo '$LANG $(pwd) `hostname` {1..3}'
$LANG $(pwd) `hostname` {1..3}

” “

Analysis of special symbols in double quotation marks


[[email protected] ~]# echo "$LANG $(pwd) `hostname` {1..3}"
en_US.UTF-8 /root znix {1..3}

No quotation marks


[[email protected] ~]# echo $LANG $(pwd) `hostname` {1..3}
en_US.UTF-8 /root znix 1 2 3

`  `

The inverted quotation marks run first, leaving the result the same as $().


[[email protected] ~]# du -sh  `find -type d`

764K    .

Chapter 2 regular expressions

2.1 What is a rule

Special Symbols Represent Text

^ Beginning

[0-9] figures

2.2 role

Improve efficiency and save time

2.3 classification

2.3.1 Basic Regular Expressions


^ $  ^$ . * .* [0-9] [^0-9]

2.3.2 extended regular expression

|  ()  +   {}  ? 

2.4 Differences between Regular Expressions and Wildcards

1. Wildcards are used to find files.

2. Regular expressions are used to find content and text in files.

2.5 Basic Regular Expressions

2.5.1 Environmental preparation

Cat-A adds a dollar sign at the end of each line.


[[email protected] ~]# oldboy.txt
I am oldboy teacher!$
I teach linux.$
$
I like badminton ball ,billiard ball and chinese chess!$
my blog is http://oldboy.blog.51cto.com$
$
our site is http://www.etiantian.org$
$
my qq num is 49000448.$
$
not 4900000448.$
my god ,i am not oldbey,but OLDBOY!$

2.5.2 Find lines starting with m^

^ m denotes beginning with m and ^ denotes beginning with what.


[[email protected] ~]# grep "^m" oldboy.txt
my blog is http://oldboy.blog.51cto.com
my qq num is 49000448.
my god ,i am not oldbey,but OLDBOY!

2.5.3 Lines ending in m$

M $denotes ending in M.


[[email protected] ~]# grep "m$" oldboy.txt
my blog is http://oldboy.blog.51cto.com

2.5.4 Displays blank lines with line numbers

– n Displays Line Number

^ Dollar means that there is nothing between the beginning and the end, that is, blank line.


[[email protected] ~]# grep -n "^$" oldboy.txt

3:

6:

8:

10:

2.5.5 represents any character. (DOT)

Points denote any character, and oldb.y denotes the location of points.


[[email protected] ~]# grep "oldb.y" oldboy.txt
I am oldboy teacher!
my blog is http://oldboy.blog.51cto.com
my god ,i am not oldbey,but OLDBOY!

Grep-o shows the grep/egrep execution process (everything found each time).


[[email protected] ~]# grep -o "." oldboy.txt
[[email protected] ~]# grep -o "oldb.y" oldboy.txt
oldboy
oldboy
oldbey

2.5.6 Find rows that end at a point

\ Conversion symbols remove the special meaning from the special meaning.

\ The $denotes ending with a dot.


[[email protected] ~]# grep '\.$' oldboy.txt
I teach linux.
my qq num is 49000448.
not 4900000448.

2.5.7 * The previous text appeared 0 or more times in a row

There have been 0 consecutive appearances, but none.

– O Displays the process of grep finding


[[email protected] ~]# grep "0*" oldboy.txt
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our site is http://www.etiantian.org
my qq num is 49000448.
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
[[email protected] ~]# grep -o "0*" oldboy.txt
000
00000

Greed of 2.5.8 Regular Expressions

As many as you want and as many matches as you can.

2.5.9. * means all

Display all the content and find it at once.


[[email protected] ~]# grep -o ".*" oldboy.txt 
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our site is http://www.etiantian.org
my qq num is 49000448.
not 4900000448.
my god ,i am not oldbey,but OLDBOY!

Represents greed when all. * appear in succession.


[[email protected] ~]# grep "^.*m" oldboy.txt
I am oldboy teacher!
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
my qq num is 49000448.
my god ,i am not oldbey,but OLDBOY!

2.5.10 [abc] brackets denote a whole

Equivalent to a symbol, representing a or B or C.


[[email protected] ~]# grep "[0-9]" oldboy.txt
[[email protected] ~]# grep "[A-Z]" oldboy.txt
[[email protected] ~]# grep "[a-z]" oldboy.txt

Find uppercase and lowercase letters in the text.


[[email protected] ~]# grep "[a-zA-Z]" oldboy.txt

2.5.11 Find lines starting with m or N or O and ending with m or G

Everything can be done in a table.

^ [m n o] m or N or o

[M G] $m or G end


[[email protected] ~]# grep "^[mno].*[mg]$" oldboy.txt
my blog is http://oldboy.blog.51cto.com
our site is http://www.etiantian.org

2.5.12 [^ a B c] Exclude a or B or C

[^ a B c] means to find characters excluding a or B or C
[[email protected] ~]# grep "[^abc]" oldboy.txt
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our site is http://www.etiantian.org
my qq num is 49000448.
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
2.5.13 grep-v exclusion and [^ abc]
Grep-v exclusion line
[^ abc] character or text

Chapter 3 Review Yesterday (Delete Files, Boot-Up Self-Start)

3.1 How does Linux make a service/script boot-up self-startup?

1)chkconfig

2)/etc/rc.local

3.1.1 What are the requirements for being managed by chkconfig

1) must be placed in / etc / init. D/

2) This script should have execution rights

3) add the content required by chkconfig.

# chkconfig: 2345 99 99

4) chkconfig — add scripts to boot-up self-startup

5) check

3.2 /etc/rc.local


[[email protected] ~]# ls -l /etc/rc3.d/ |grep rc.local
lrwxrwxrwx. 1 root root 11 Aug 10 18:36 S99local -> ../rc.local

3.3 Insufficient disk space no space left on device

1) Block full of 500G 3*200G video


 df -h
 du -sh /*
 du -sh /* |grep G

2) The number of hard links that have not been completely deleted is 0 and the number of process calls is not zero.

Check: lsof | grep delete

3.4 File Deletion Principle (Conditions)

1. Hard Link Number 0

2. The number of process calls is 0

Journal


/var/log/messages
/var/log/secure
rsyslog

3. Inode is full

Creating a file takes up one inode and at least one block

Lots of small files

summary

The above is the special symbols and regular expressions in Linux introduced by Xiaobian to you. I hope it can help you. If you have any questions, please leave a message to me, and Xiaobian will reply you in time. Thank you very much for your support to developpaer.

Recommended Today

The method of obtaining the resolution of display by pyqt5

The code is as follows import sys from PyQt5.QtWidgets import QApplication, QWidget class Example(QWidget): def __init__(self): super().__init__() self.initUI() #Interface drawing to initui method def initUI(self): self.desktop = QApplication.desktop() #Get display resolution size self.screenRect = self.desktop.screenGeometry() self.height = self.screenRect.height() self.width = self.screenRect.width() print(self.height) print(self.width) #Show window self.show() if __name__ == ‘__main__’: #Create applications and objects app […]