List files which does not contain a string

root# grep -rL "string"

Explanation:
-r makes grep recursively
-L only output a filename when it does not contain “string”

Example:
[greg@localhost test123]$ ls -la
total 20
drwxrwxr-x. 2 greg greg 4096 Jun 2 11:31 .
drwx——. 18 greg greg 4096 Jun 2 11:30 ..
-rw-rw-r–. 1 greg greg 4 Jun 2 11:31 aaa.text
-rw-rw-r–. 1 greg greg 4 Jun 2 11:31 bbb.text
-rw-rw-r–. 1 greg greg 4 Jun 2 11:31 ccc.text
[greg@localhost test123]$ cat *
123
213
212
[greg@localhost test123]$

greg@localhost test123]$ grep -rL “123”
ccc.text
bbb.text
[greg@localhost test123]$

Leave a Reply

Your email address will not be published. Required fields are marked *

*