Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use regular expressions in Linux

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report