Searching file content
Linux Command Line Quick Reference
1 min read
This section is 1 min read, full guide is 20 min read
Published Aug 18 2026
19
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
CLILinuxUbuntu
grep searches text for matching lines. It works on files directly or on output received through a pipe.
Search text with grep
bash
grep "error" app.loggrep -i "error" app.loggrep -n "error" app.loggrep -R "database_url" /etc/myappgrep -E "error|warning" app.loggrep -v "debug" app.loggrep -w "root" /etc/passwdjournalctl | grep -i "failed"-i ignores case. -n includes line numbers. -R searches recursively and follows symbolic links encountered on the command line. -r is recursive without that behaviour. -E enables extended regular expressions. -v inverts the match, returning lines that do not match. -w matches complete words.
Use -A N, -B N or -C N to show lines after, before or around a match. -l prints only filenames containing matches and -c prints a count of matching lines.