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 grep Command in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article uses easy-to-understand examples to introduce the use of grep commands in linux, the code is very detailed, interested friends can refer to, hope to be helpful.

Grep

Grep is a powerful text search tool that uses regular expressions to search for text and print matching lines.

Common syntax:

[root@www ~] # grep [- acinv] [--color=auto] 'search string' filename

Options and parameters:

-a: search binary files for data in the form of text files

-c: calculates the number of times a 'search string' is found

-I: ignore the case difference, so the case is considered the same

-n: output line number

-v: reverse selection, that is, the line that shows no 'search string' content

-- color=auto: you can color the keywords you find.

For example:

Take out the line where root appears in / etc/passwd

# grep root / etc/passwdroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin or # cat / etc/passwd | grep root root:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin

Take out the lines where root appears in / etc/passwd and display the line numbers of these lines in / etc/passwd

# grep-n root / etc/passwd1:root:x:0:0:root:/root:/bin/bash30:operator:x:11:0:operator:/root:/sbin/nologin this is the end of the usage of the grep command in linux. I hope the above content can be of some help and learn more. If you think the article is good, you can share it for more people to see.

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