Jeremy's Notes

The Reverie of a Techie


Differences

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

Link to this comparison view

Next revision
Previous revision
blog:linux_search_file_contents [2021/01/02 14:48] – created Jeremy McReynoldsblog:linux_search_file_contents [2021/01/09 15:47] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== How to find files containing specific text in Linux? ====== ====== How to find files containing specific text in Linux? ======
 +{{ :blog:linux_search_file_contents.png?nolink&150|Penguin by Lars Meiertoberens from the Noun Project}}
 If you would like to find a specific string of text within a directory of files, you can use the following command and example: If you would like to find a specific string of text within a directory of files, you can use the following command and example:
-<code>grep -rnw '/path/to/directory/' -e 'searchterm'</code>+<code bash>user@host:~$ grep -rnw '/path/to/directory/' -e 'searchterm'</code>
  
-Here's a breakdown of the aforementioned example command and search parameters:+Here's a breakdown of the example command and its parameters:
   * ''-r'' or ''-R'' will recursively (within directories) look at all files within the specified path.   * ''-r'' or ''-R'' will recursively (within directories) look at all files within the specified path.
   * ''-n'' will display the line number where the term shows up within each file.   * ''-n'' will display the line number where the term shows up within each file.
   * ''-w'' Matches the whole word.   * ''-w'' Matches the whole word.
  
 +===== Sources =====
 +  * [[https://linuxcommand.org/lc3_man_pages/grep1.html|grep Manpage]]
 +
 +===== Share =====
 ~~socialite~~ ~~socialite~~
 +===== Tags =====
 {{tag>Linux How-to}} {{tag>Linux How-to}}
 ~~DISCUSSION~~ ~~DISCUSSION~~
 ~~Article~~ ~~Article~~
 +~~NOTOC~~
blog/linux_search_file_contents.1609616921.txt.gz · Last modified: 2021/01/09 15:47 (external edit)