bash grep command-line text-processing

grep Basics

`grep` searches for patterns in files. It's one of the most useful commands you'll ever learn.

The name stands for "Global Regular Expression Print"—but you don't need regex to use it. Start simple.

bash
# Search for "error" in a file
grep "error" logfile.txt

# Case-insensitive search
grep -i "error" logfile.txt

# Show line numbers
grep -n "error" logfile.txt

# Search recursively in directories
grep -r "TODO" ./src

# Invert match (lines that DON'T contain)
grep -v "debug" logfile.txt
Command Line Confidence

This tip is from

Command Line Confidence

100 more tips like this one.

Get the Book