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.

0

5 Answers 5

24

Use:

grep -lir "helo" /path/to/dir
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

2
  • 1
    That's a lot of typing when you can just grep -r
    – hookenz
    Sep 21, 2011 at 12:05
  • With the Command find you can grep recursive through directories and grep in all files.
    – kockiren
    Sep 22, 2011 at 7:28
1

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

1

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

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.

You must log in to answer this question.