Suppose that I have a directory with name _file and includes two sub directory like _1 and _2 and on each one I have some text files. I want to search a word like foo in one of these text files. How I can do that? I want to know which text files in the whole directory contain that word?
If you don't want to install additional software, you can simply use
grep
in the terminal. To recursively search through directories, you can use the-r
option (seeman grep
for details). The syntax you are looking for is probably:So, for instance if I want to search for the string "asdf" in all files in all subdirectories of "/tmp/testdir/" the command looks like this:
The quotation marks are not strictly necessary, but if your string or directory path contains whitespaces, you otherwise would have to mask them using the \ character...
ack-grep
by typingsudo apt-get install ack-grep
ack-grep foo
. it lists out all the matches in all files under that directory.You can use recursive
grep
with the-l
flag to only print the file's name instead of the matched line:Or, you can use
find
:Or. you can use
extglob
and normalgrep
Just install
gnome-search-tool
usingsudo apt-get install gnome-search-tool
Search in dash for 'search for files' and launch it.
See image below:
Enjoy.