The file contains the following line


I got the line from the following command

cat * | grep google

However, I do not know its location.

How can you get the precise location of the file without Ack?

  • My answer notwithstanding, you should install Ack. After all, it's better than grep. :) – Telemachus Jun 7 '09 at 13:30
  • @Telemachus: I know it is better, but it would require me to configure my PATHs at Bluehost, which would be a pain, since I do not have sudo access. – Léo Léopold Hertz 준영 Jun 7 '09 at 14:13
  • 1
    Fair enough, but if you plan to use that site for any significant amount of Perl work, you should look into the local::lib module. It allows you to install modules in local directories quite easily. It doesn't require super-user privileges: search.cpan.org/~apeiron/local-lib-1.004001 – Telemachus Jun 7 '09 at 16:06
  • Ack also comes in a handy standalone version that doesn't need anything. Download one single file and run it. – Andy Lester Dec 1 '10 at 23:59

For the general class of problem you're describing, to find the file you could run

grep -r 'google.friendconnect' /

Where ‘/‘ would be whatever directory path you want to search. This will recursively search all files in that directory tree for that string. The specific command presented will take a while, and will produce a lot of ‘Permission Denied’ errors unless you run it as root. Since it will be search proc, var, sys, and other users home directories. Another useful option to grep that you probably also want is ‘-n’. That will also print out the line number of the file that matched. Such as,

grep -n 'google.friendconnect' *

I find that 90% of the time I use the options ‘irn’ for grep: case insensitive, recursive, and print line numbers.

  • 1
    If he's starting from "cat * | grep google", then I think he knows what directory the file is in. That is, he doesn't need to go so far as "grep -r 'something' /" - which will take a long, long time and produce so many Permission denied errors that good output will get lost in the flood. – Telemachus Jun 7 '09 at 13:28
  • My intent here was to solve the class of problems, not necessarily the specific problem. Given the option, solving the class is always better. Edited to clarify. – Scott Pack Jun 7 '09 at 13:39
  • 1
    I'm sorry, but this is a terrible general answer for this class of problems. You rarely have such limited information that you have to start from the root directory of the entire machine. This is a huge waste of time and resources for this kind of problem. If anything, at least start from the root of the user's $HOME. How likely is it that the file he wants is in /proc or /dev or /etc or /bin? – Telemachus Jun 7 '09 at 13:47
  • Actually, I see that you've clarified that you don't necessarily mean '/' as root. However, the bulk of your answer still implies that you are going to search through directories that the user no permission for. That alone should suggest that this is the wrong approach. You might want to edit again to really highlight that you almost never want to search starting literally from '/'. – Telemachus Jun 7 '09 at 13:51
  • 1
    @Telemachus: I agree with Telemachus. It is better to use grep ... connect' * to search only the current directory in hand or ~ to search HOME. – Léo Léopold Hertz 준영 Jun 7 '09 at 13:55

Try the -H flag for grep. Also, don't use cat there, please. It isn't necessary.

grep -H google *

To clarify, the -H flag forces grep to print the filename. After thinking it over, I remembered that the -H flag is the default when you search more than one file. So, in this case it's redundant. Andy's answer is really simpler and right.


grep google *

(instead of using cat, give grep a list of file names and it will print the name of the files matching when it prints the lines)


An optimal way to search the string in all files under a directory to print matching files with line numbers on the matched line would look like this from the base directory.

grep -Hn <string_of_interest> `find . -type f`

That is without using AWK (which is what you meant i guess).


Your Answer

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

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