-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
use-grep-to-search-multiple-files-at-once.scroll
47 lines (29 loc) · 1.31 KB
/
use-grep-to-search-multiple-files-at-once.scroll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
date 2009-11-22
tags index
permalink use-grep-to-search-multiple-files-at-once.html
title Use grep to search multiple files at once
pageHeader.scroll
`grep` lets you search through multiple text files at once.
I recently removed a feature from a project and wanted to make sure I removed all references to it. With grep it was easy:
code
grep -r picture *
This searched all the files in my current directory as well as all the files in each subdirectory, and printed the filename and line where the word "picture" appeared.
Then I went in and changed the 2 files that needed modifying.
Had I wanted to just search the current directory (without the subdirectories) I could have done:
code
grep picture *.*
This would have searched through all the files in the current directory.
Had I wanted to search in just 1 specific file:
code
grep picture filename.txt
Had I wanted to do a case insensitive search:
code
grep -ir picture *
Had I wanted to exclude a directory and done a case insensitive search:
code
grep -ri "searchstring" --exclude="*\.svn*" *
(grep uses regular expressions)
# Links
- <a href="https://en.wikipedia.org/wiki/Grep">grep</a> on Wikipedia
- <a href="https://stackoverflow.com/questions/221921/grep-exclude-include-syntax-do-not-grep-through-certain-files">Stackoverflow</a> grep help
footer.scroll