Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Sylvain Pineau, Warren Hill, waltinator, BuZZ-dEE, belacqua May 7 '14 at 22:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

the question here shows two options to recursively search a whole directory for the occurrence of strings in textfiles:… – Jacob Vlijm May 7 '14 at 12:17
Your question is not clear. Do you want to use a terminal command (obviously, but that belongs to the basics of Unix like system learning, you can google that yourself), a given software or what ? – user284234 May 7 '14 at 12:19
@begueradj I did not now there are any softwares for this. So I asked general;) – lion May 7 '14 at 12:26
up vote 1 down vote accepted
  1. Open a terminal.
  2. Install ack-grep by typing sudo apt-get install ack-grep
  3. Change to the directory you want to search under, and type ack-grep foo. it lists out all the matches in all files under that directory.
share|improve this answer

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 (see man 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:

grep -r "asdf" "/tmp/testdir/"

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...

share|improve this answer

Just install gnome-search-tool using sudo apt-get install gnome-search-tool
Search in dash for 'search for files' and launch it.

See image below:

enter image description here

  1. Leave the 'name contains' section empty.
  2. Select your folder.
  3. Unfold the 'select more options' part and choose 'contains the text' and then press add.
  4. Type here the text you want to search for and click find at the bottom right corner.


share|improve this answer

You can use recursive grep with the -l flag to only print the file's name instead of the matched line:

grep -Rl foo .

Or, you can use find:

find . -type f -exec grep -l foo {} +

Or. you can use extglob and normal grep

shopt -s extglob
grep -l foo **/*
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.