Search
The grep command
Searches a pattern inside files and shows only the matching lines.
Syntax
grep [opciones] <patrón> [archivo]Most useful options
-iIgnores upper and lower case-vShows the lines that do NOT match-nNumbers the lines-rSearches inside every file of a folderCopy-ready examples
$ grep mkdir Documentos/tareas.txtSearch in a file$ grep -i bash Documentos/apuntes.txtCase-insensitive$ grep -rn bash .In the whole folder, with numbersYou can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- By default it is case-sensitive.
FAQ
Does grep search files or text?
It searches text inside files. To find files by name you use find.
How do I count the matches?
Pipe it to wc -l: grep -r word . | wc -l.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course