Content
Go-to Command:
-a
Includes hidden files/dirs.
-I
Ignore binaries (.bin, .jpg, etc)
-R
Recursive + follows all symlinks
-i
Case-insensitive
-l
Shows only filenames with pattern in the content
grep -IRil "password|passphrase|secret" /path/to/search
Multiple keywords
grep -IRil --include=*.txt "pattern" /path/to/search
File extensions
grep -v "pattern" /path/to/search
Inverse
grep -vE "(pattern1) | (pattern2)" file.txt
Multiple inverse patterns
zgrep -Iil "pattern" /path/to/search
Basic pattern match
zgrep -Iil "pattern1|pattern2|pattern3" /path/to/search
Multiple keywords (Compressed files)
zgrep -Iil --include=*.gz "pattern" /path/to/search
File extensions (Compressed files)
find / -a -type f -name "*.gz" -exec zgrep "pattern" {} +
Recursive zgrep
find / -a -type f -exec grep -Iil "pattern" {} + 2>/dev/null
Search the contents of all files for string. Return filenames.
find / -a -type f -name "*.java" -exec grep -il 'pattern' {} \;
Ignore case with -i option
find / -a -type f -empty -exec ls -l {} \;
Empty Files
find / -a -type f -name "*.gz" -exec zgrep 'pattern'{} \;
Search for a string in gzip'd files
Last updated
Was this helpful?