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

Linux four swordsmen find, grep, sed, awk finishing

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Linux four swordsmen find, grep, sed, awk finishing find is mainly used to find the path of a file or directory in the Linux operating system, and to find out the path of the file or directory that meets the conditions find /-name *. Rpm-type d-- # # /: indicates that the search is carried out in the root directory # #-type: the type of search, d is the directory F is a normal file find /-name "con*.log"-exec cp {} / tmp/\ # finding Linux systems based on find ends with .log and the name begins with con At the same time, copy it to the / tmp directory to find-name filename to find a file named filename-type b/d/c/p/l/f to find block devices / directories / character devices / pipes / symbolic links / normal files-size n [c] to find long Files in n blocks or n bytes-mtime-n + n look up by file change time-n means within n days-atime by file access time-ctime Take the file creation time-nmin n as an example: find / data/-name "* .text" find / data/-name "[Amurz] *" files beginning with lowercase letters find / data/!-type d find non-folder find / Data/-type l looks up the linked file find / data/-type d | xargs chmod 755-R looks up directory types and sets permissions to 755 find / data/-size + 1m find / data/-size 1m find / data/-mtime + 30-name "* .log" Comprehensive Application: find / data/-name "* .log"-type f-size + 10m-exec cp {} / tmp/\ Find / data/-name ""-type f-mtime + 30-size + 10m-exec mv {} / tmp/\; grep

The common parameters of grep are as follows:

-a search as a text file-c calculates the number of compound lines found-n output line number-v outputs non-own characters-h does not display file names-l outputs only files containing matching characters ming

Examples are as follows:

Grep-c "root" / etc/passwd Statistics the total number of lines of root grep-I "root" / etc/passwd ignores uppercase and lowercase grep-n "root" / etc/passwd prints lines of root or line number grep-v "root" / etc/passwd does not print root's hang grep "root [53]" / etc/passwd characters that begin with root The next 5 or 3 lines grep "^ [^ root]" / etc/passwd output lines that do not begin with root grep "r\ {2,\}" / etc/passwd print r characters appear more than twice in a row grep-n "^ $" / etc/passwd line number of blank lines grep-- color-E "\ > ([0-9] {1pm 3}\. {3}) [0-9] {1pm 3}" match ipv4 address sed

Sed is a non-interactive text editor that processes one line of content at a time

Awk

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

Servers

Wechat

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

12
Report