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 the grep command in linux

2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

This article mainly introduces how to use the grep command in linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

We know that we can use cat to view the contents of a text file, but sometimes we don't need to see all the contents, but we need to see a line that contains some information. For example, in *, we need to check whether some configuration files contain some sensitive information, such as password information, database connection information, etc., so we can quickly view what we need to see by using grep!

The usage syntax is as follows:

Grep finds the file for which the content is to be found

If the search contains spaces, then you need to add 'single quotation marks', such as: grep 'test hh' filenema, and you can find it in multiple files, just continue to add the file name later!

Root@kali:~/linuxcmd# grep root / etc/passwdroot:x:0:0:root:/root:/bin/bashroot@kali:~/linuxcmd#root@kali:~/linuxcmd# grep root / etc/passwd / etc/shadow/etc/passwd:root:x:0:0:root:/root:/bin/bash/etc/shadow:root:$6 $8uR2a64J$y2Oc5C6QsTRtJ1tpfpJKDIAfXzSM8rJ0IizfM32Mn.ac.UBUGgtq1HT2kgvnx4LFGukbj/poLJzg32VjpTbJS.:17103:0:99999:7:::root@kali:~/linuxcmd#

Because linux is case-sensitive and grep is case-sensitive, you need to add the-I parameter if you want to be case-insensitive!

Root@kali:~/eth20/eth20# grep hello test.txthello eth20 rootless kalifrel raceme eth20 grep-I hello test.txthello eth20 hello ETH10 rootball kalifreur rootball kalifret

The common parameters of grep are as follows:

-I is not case sensitive

-c statistics contain matching rows of data

-n output line number

-v reverse matching

Thank you for reading this article carefully. I hope the article "how to use grep commands in linux" shared by the editor will be helpful to all of you. At the same time, I hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Network Security

Wechat

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

12
Report