Note -r searches recursively through directories. -n shows line numbers. -i is case-insensitive. -v inverts the match (shows non-matching lines). -c counts matches. -l lists only filenames with matches. Use -E for extended regex or egrep.
search textfind in filesgrep patternsearch stringregex searchfind TODO
Stream Editor for Find & Replace
syntax
sed [options] 's/pattern/replacement/flags' file
example
sed 's/localhost/0.0.0.0/g' config.ini
sed -i.bak 's/v1\.2/v1.3/g' version.txt
sed -n '10,20p' access.log
sed '/^$/d' notes.txt
Note -i edits in place. -i.bak creates a backup before editing (strongly recommended). g flag replaces all occurrences on a line, not just the first. -n suppresses default output; use with p to print specific lines. /d deletes matched lines.
find and replacesed substituteedit in placestream editorreplace textdelete lines
192.168.1.40 [28/Mar/2026:10:15:23
Alice 2340
Total: 87450
Note By default, awk splits on whitespace. -F sets a custom delimiter. $0 is the whole line, $1 is the first field, NR is the line number, NF is the number of fields. BEGIN runs before processing; END runs after.
Note -d sets the delimiter (default is tab). -f selects fields by number. -c selects character positions. For more complex extraction, awk is usually more flexible.
Note tr reads only from stdin (it cannot take a filename argument). -d deletes characters in set1. -s squeezes repeated characters. Converting \r is handy for fixing Windows line endings.
lowercaseuppercasetranslate charactersdelete charactersreplace characterfix line endings
Note -0 with find -print0 handles filenames with spaces and special characters safely. -I {} replaces {} with each input line. -P runs N processes in parallel for significant speedups on I/O-bound tasks.
pipe to commandbuild commandxargs parallelbatch commandstdin to args
Split Output to File and Stdout
syntax
tee [options] file...
example
make build 2>&1 | tee build.log
echo'new entry' | sudo tee -a /etc/hosts
Note -a appends instead of overwriting. tee is essential for writing to root-owned files because 'sudo echo x > /root/file' fails (the redirect runs as your user, not root). Use 'echo x | sudo tee /root/file' instead.
save and displaywrite to file and stdouttee appendsudo write filesplit output
Format Tabular Output
syntax
column [options]
example
cat data.csv | column -t -s','
mount | column -t
output
name age department
Alice 30 Engineering
Bob 25 Marketing
Note -t creates a neatly aligned table. -s sets the input delimiter. Great for making CSV data or command output readable in the terminal.
format tablealign columnspretty printtabular output
Note -d sets the delimiter (default is tab). Using - multiple times reads successive lines from stdin into columns. The seq example arranges 1-10 into a 4-column layout.