Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I am stuck up with a problem I have a line 'something' in some file. In which file is this line that I have forgotten. In the entire root file system I would like to find out which file and where is this line. So how can I go for this.I have used find but when I used find then I knew the name of file in this case I do not know name of file also. It is a Ubuntu server 10.04 So what can I do to find out which file has this string.

share|improve this question
up vote 2 down vote accepted

I always use:

find / -xdev | xargs grep "string"

That'll give you a list of all of the matched strings along with the actual files they're in.

share|improve this answer

A simple bruteforce solution would be:

find / -type f -exec grep -H 'some string' {} \;

(the -H option to gnu grep causes it to return the filename).

However you'd probably benefit from spedning the time writing a smarter script which ignores stuff like binary files, executables (non-script) etc.

share|improve this answer
If you do this, make sure you add -xdev or otherwise avoid going into /proc and /sys; you can search through those for a really long time without finding anything useful. – MadHatter Feb 24 '11 at 14:02
Yeah, I really recommend giving the -I flag to grep, so that binary files are treated as non-matching. Really cuts down on the false positives. – Christopher Karel Feb 24 '11 at 15:16
Using xargs or -exec ... +, if your find supports it, will speed things up. – Dennis Williamson Feb 24 '11 at 15:38

heh well there are a lot of files

maybe if you could narrow it down to some time when you last accessed that file and try

find / -xdev -type f -atime -X -exec grep -H 'string' {} \;

where X is number of days from today backwards in which you are sure you accessed the file

share|improve this answer

Perhaps something like ' grep -iR "text to find" * ' run from the root will do it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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