User Tools

Site Tools

tools:grep

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:grep [2024/09/28 02:55] – [Useful Commands] Humphrey Boa-Garttools:grep [2026/03/31 12:23] (current) – [External Links] Humphrey Boa-Gart
Line 23: Line 23:
 ==== Search Files in Current Directory ==== ==== Search Files in Current Directory ====
  
-You can also use grep to search inside all the files within a folder, and not just one. Just replace the filename with an asterisk. To search the PWD for all files containing //INSERTSTRING//, format your command as so:+You can also use ''grep'' to search inside all the files within a folder, and not just one. Just replace the filename with an asterisk. To search the pwd for all files containing //INSERTSTRING//, format your command as so:
  
   $ grep “INSERTSTRING” *   $ grep “INSERTSTRING” *
Line 35: Line 35:
   $ grep “INSERT*” *.txt   $ grep “INSERT*” *.txt
  
-The ''-R'' flag lets you search child directories. So to search your PWD **and** all child directories recursively for all files containing //INSERTSTRING//:+The ''-R'' flag lets you search child directories. So to search your pwd **and** all child directories recursively for all files containing //INSERTSTRING//:
  
   $ grep -R "INSERTSTRING" *   $ grep -R "INSERTSTRING" *
  
-You can combine flags as well. To search your PWD and all child directories recursively for all //.txt// files containing //INSERTSTRING//, and to make grep tell you the line number that the string is found on, combine the ''-R'' and ''-n'' flags like this:+You can combine flags as well. To search your pwd and all child directories recursively for all //.txt// files containing //INSERTSTRING//, and to make grep tell you the line number that the string is found on, combine the ''-R'' and ''-n'' flags like this:
  
   $ grep -Rn "INSERTSTRING" *.txt   $ grep -Rn "INSERTSTRING" *.txt
Line 55: Line 55:
  
  
 +==== More Command Flags ====
 +
 +There are more flags you can combine with these basic ''grep'' commands to fine-tune your search. Play around with them to see how they affect output!
 +
 +  * ''-i'' - Searches made with ''grep'' are case-sensitive. Use this flag to search for both uppercase and lowercase versions of the same string.
 +  * ''-l'' - Print only the filename(s) of search results. Incredibly useful when using ''-R'' on large directory trees.
 +  * ''-w'' - Match only whole words.
 +  * ''-x'' - Match only whole lines.
 +  * ''-v'' - Inverted search. Returns only non-matching lines.
 +  * ''-s'' - Suppress error messages. Useful in bash scripts.
 ===== Variations ===== ===== Variations =====
  
Line 67: Line 77:
 The DOS, OS/2 and Windows platforms provide the ''find'' command for simple string searches. Windows also provides the ''findstr'' command which approximates much of the functionality of ''grep'', or you can use the the ported version in [[tools:cygwin|Cygwin]]. The DOS, OS/2 and Windows platforms provide the ''find'' command for simple string searches. Windows also provides the ''findstr'' command which approximates much of the functionality of ''grep'', or you can use the the ported version in [[tools:cygwin|Cygwin]].
  
-===== External Links =====+===== Further Reading =====
  
-[[https://www.gnu.org/software/grep/|Official page for grep at the GNU Project]]+  * [[https://www.gnu.org/software/grep/|Official page for grep at the GNU Project]] 
 +  * [[rfc>9485|RFC 9485]] - Standardized specification for regular expressions used by grep.
  
  
 {{tag>Tools}} {{tag>Tools}}
tools/grep.1727492143.txt.gz · Last modified: (external edit)

Find this page online at: https://bestpoint.institute/tools/grep
CC Attribution-Noncommercial-Share Alike 4.0 International The Anonymous Fruit Company The East Internet Trading Company Erischan Novelty Lanterns

Copyright 2026 Best Point Holdings Limited