Get the App
SLTechnology News&Howtos  ›  Network Security  › 

How to use the grep command in linux

Shulou Source: shulou.com Published: 2022-06-01 00:06:24 10月03日 Update

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!

Tags: Content files information articles size commands parameters data one line value interest can be passed simultaneously multiple passwords to uppercase lowercase commonly used quotation marks database Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Technology MySQL OPPO Reno Linux