Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use regular expressions in Linux

Shulou Source: shulou.com Published: 2022-06-02 09:54:54 09月27日 Update

Linux regular expressions in how to use, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

1. Find out the local IPv4 address in the result of ifconfig "network card name" command.

Ifconfig | head-n 2 | tail-1 | tr-s "" | cut-d ""-f3

2. Find out the maximum percentage of space utilization in the zone.

Df | tr-s "" | cut-d ""-f5

3. Find out the user name, UID and shell type of the maximum UID of the user

Cat / etc/passwd | cut-d:-F1 Magi 3 sort 7 | sort-nt:-K2 | tail-n 1

4. Find out the permissions of / tmp

Stat / tmp | head-n 4 | tail-n 1 | cut-c10-13

5. Display the user names and UID of all system users on the CentOS8

Cat / etc/passwd | cut-d:-F1 Magazine 3 | egrep-v "[0-9] {4,}"

6. Display the UID and default shell of three users root, linuxmi, mi (A8 instead)

Cat / etc/passwd | egrep "^ (root | A8)" | cut-d:-F1

7. Use egrep to extract / etc/rc.d/init.d/functions the characters that match the conditions in the file.

Echo / etc/rc.d/init.d/functions | egrep "[a murz] $"

8. Use egrep to retrieve the directory name of the above path

Echo / etc/rc.d/init.d/functions | egrep "/. * /"

9. Count the number of times each host logged in with root IP address in the last command

10. Extended regular expressions are used to represent 0-9, 10-99, 100-199, 200-249, 250-255, respectively.

Echo {1.. 255} | egrep "\"

Egrep "\"

Egrep "\"

Egrep "\"

Egrep "\"

11. Display all IPv4 addresses in the results of the ifconfig command

Ifconfig | egrep "[0-9] {1Pert 3}. [0-9] {1pr 3}. [0-9] {1pr 3}. [0-9] {1pr 3}"

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: User command address regular expression maximum user name result help login clear three host usage content character this file article novice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Docker Microsoft Shulou Information Shulou Technology