Terminal - Search entire directory for keyword
20,927
Solution 1
You can use the recursive mode of grep:
grep -R pattern directory
ack
(ack-grep
on Ubuntu) and ag
are also good for this.
Solution 2
cd ~/path/to/your/directory
grep -rwI KeywordCaseSensitive *
Explanateion:
-r
search recursively
w
search for a word only (i.e. surrounded by white space and/or punctuation)
I
ignore binary files
You may consider option -i
(ignore case).
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
I am working on a Ruby on Rails project so I have to manage multiple files. I think I made a syntax mistake somewhere but I'm not sure well. It would be awesome if I could search for a keyword through the entire project directory.
I'm sure there's some command on Terminal, but I'm not sure what it is.
-
Avinash Raj about 10 yearsdid you want to find the files which contain a specific keyword?
-
-
terdon about 10 years+1 but
ack
? You meanack-grep
? And what isag
? Did you meanagrep
? -
Volker Siegel about 8 yearsI think it should be option
-r
(--recursive
) instead of-R
(--dereference-recursive
), as-R
would follow symlinks out of the project directory.