14

How can I find a file by its content on Linux in the command line?

For example, I want to find a file containing the word "helo" on my computer.

24

Use:

grep -lir "helo" /path/to/dir
| improve this answer | |
3

You can create a file named grepall in /usr/local/bin/ with following content:

find -type f -exec grep -q $1 {} \; -print

then you can search for content by use grepall something

| improve this answer | |
  • 1
    That's a lot of typing when you can just grep -r – Matt H Sep 21 '11 at 12:05
  • With the Command find you can grep recursive through directories and grep in all files. – kockiren Sep 22 '11 at 7:28
1

egrep -R "hello" /path/to/dir

| improve this answer | |
1

Evil way: grep "something" */*/*

| improve this answer | |
0

If you're an admin or coder, you might consider ripgrep instead of the usual grep.

rg helo for example searches all files in the current working directory (incl. subfolders).

For more detailed information, consult the guide, the man page or even the code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy