grep basic usage

Updated: 10 January 2025

Find all occurrences of foo in directories and files recursively, from the current directory

# -i: case insensitive
# -r: recursive but don't follow symlinks
# -n: show line number
# --text: treat binary files as text

grep -irn --exclude-dir=dir --text foo *

Interpret PATTERNS as --fixed-strings, not regular expressions

grep -F './dir/dir2' file.txt

Read-in a long regex, from a file

cat grep-me.log | grep --file=long-regex.txt

Leave a comment