File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
10
10
For a steady stream of TILs from a variety of rocketeers, checkout
11
11
[ til.hashrocket.com] ( https://til.hashrocket.com/ ) .
12
12
13
- _ 698 TILs and counting..._
13
+ _ 699 TILs and counting..._
14
14
15
15
---
16
16
@@ -634,6 +634,7 @@ _698 TILs and counting..._
634
634
- [ Globbing For All Directories In Zsh] ( unix/globbing-for-all-directories-in-zsh.md )
635
635
- [ Globbing For Filenames In Zsh] ( unix/globbing-for-filenames-in-zsh.md )
636
636
- [ Grep For Files Without A Match] ( unix/grep-for-files-without-a-match.md )
637
+ - [ Grep For Files With Multiple Matches] ( unix/grep-for-files-with-multiple-matches.md )
637
638
- [ Grep For Multiple Patterns] ( unix/grep-for-multiple-patterns.md )
638
639
- [ Hexdump A Compiled File] ( unix/hexdump-a-compiled-file.md )
639
640
- [ Jump To The Ends Of Your Shell History] ( unix/jump-to-the-ends-of-your-shell-history.md )
Original file line number Diff line number Diff line change
1
+ # Grep For Files With Multiple Matches
2
+
3
+ The ` grep ` utility is a great way to find files that contain a certain
4
+ pattern:
5
+
6
+ ``` bash
7
+ $ grep -r " .class-name" src/css/
8
+ ```
9
+
10
+ This will recursively look through all the files in your css directory to
11
+ find matches of ` .class-name ` .
12
+
13
+ Often times these kinds of searches can turn up too many results and you'll
14
+ want to pare it back by providing some additional context.
15
+
16
+ For instance, we may only want results where ` @media only screen ` also
17
+ appears, but on a different line. To do this, we need to chain a series of
18
+ ` greps ` together.
19
+
20
+ ``` bash
21
+ $ grep -rl " @media only screen" src/css |
22
+ xargs grep -l " .class-name"
23
+ ```
24
+
25
+ This will produce a list of filenames (hence the ` -l ` flag) that contain
26
+ both a line with ` @media only screen ` and a line with ` .class-name ` .
27
+
28
+ If you need to, chain more ` grep ` commands on to narrow things down even
29
+ farther.
30
+
31
+ See ` man grep ` for more details.
You can’t perform that action at this time.
0 commit comments