1

My .htaccess file in my htdocs folder does not work. I tried to redirect to Google when accessing a filename. I want to find out where the settings for my httpd.conf are, so I can enable mod_rewrite. I did the following UNIX command to find out if a httpd.conf file existed on my hard drive:

find * -name "httpd.conf" 

The file does not exist. I am thinking that maybe there is another file that controls mod_rewrite. I want to see if "AllowOverride" exists in any directory. I entered the following UNIX command:

grep -r "AllowOverride" * 

But it's hard to read because it prints out so many folders. The message that accompanies the folders are "Permission denied" or "No such file or directory". How do I only get the file paths of files that contain AllowOverride?

2
  • 1
    Try suppressing stderr with 2> /dev/null Commented Jun 29, 2012 at 22:50
  • 3
    You're using find incorrectly. Don't use * for your path; use . or / or something else instead. One path only... Commented Jun 29, 2012 at 22:50

3 Answers 3

5

Many Unix and similar systems provide a locate(1) command that uses a database to speed finding individual files. Try this:

locate httpd.conf 

Note, of course, that Apache configurations are stored in files of all sorts of names; I've seen apache.conf, httpd.conf, httpd2.conf, and then there's the giant pile of /etc/apache2/conf.d/ -- entire directory structures set aside for configuring Apache. Your distribution may vary.

Perhaps apachectl configtest will show the paths? (currently not installed on my machine, so I can't easily test.)

Sign up to request clarification or add additional context in comments.

Comments

4

Try this command:

 find / -name "httpd.conf" 2>1 | grep -v "Permission denied" 

the 2>1 funnels stderr to stdout so that both can be piped into the grep utility. grep in turn will print anyline that doesn't have the string "Permission denied" in it (the -v negates/inverts the matching of the search string)

If you don't redirect stderr to stdout, the output of stderr to the console would bypass the rest of the command line.

You could extend the above command line by appending this:

| grep -v "No such file or directory" 

if that string was coming up and you wanted to suppress it too.

This tells you all about io redirection. And here's a nice quick summary.

4 Comments

Another nice option is to just throw away all the errors: find / -name httpd.conf 2> /dev/null.
@sarnold .. that's true, I like to have them though, just in case I want to filter on them (and I'm lazy, so I'll just use the same initial command line). locate is a good solution as long as updatedb runs regularly. I once worked at a place that didn't have a cron job and I didn't have sudo to run it :-(
Eeep, no updatedb database, that'd be so tiring... hooray for locate. :)
@sarnold Agreed. For a long time, before I figured out find I was depending on locate only (and usually query it first)
1

Use the following:

 find / -type f -exec grep -n "AllowOverride" {} \; -print 2>/dev/null 

To scan files containing the "AllowOverride" string from the root, if you want to run the search in a particular directory, use the following instead:

 find /path/to/directory -type f -exec grep -n "AllowOverride" {} \; -print 2>/dev/null 

The output should only print the files containing the specified string along with the number of the matching line

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.