Find all .htaccess files with a particular php configuration setting

After some testing on a server with a strange setup I needed to find all of the .htaccess files that might contain a particular php configuration directive. The pattern was unique enough that I would have probably just done a recursive grep for it in any other circumstance. But by default “grep -R someSearchString *” would ignore dot files like .htaccess, and on a bigger server this could have grep looking through a lot of files when I knew I only wanted to search .htaccess files. “grep -R someSearchString .*” would be just bad since it would recurse into the ‘..’ directory, so you would end up searching your whole harddrive.

The solution? “find”

$ cd /home
$ sudo find ./ -iname ".htaccess" -exec grep -H some_php_config {} \;
./someuser/httpdocs/.htaccess: some_php_config some_value

Sudo runs the command as root, since I’m looking in everyones’ home directories. find is the command that is actually looking for the files. Then it passes the matches to grep. The -H flag on grep gives you the name of the files, without it you would just get the matching lines from the files, but no indication which files they were in.

Just find all .htaccess files

In some cases it’s just nice to be able to find all of the .htaccess files

$ sudo find ./ -iname ".htaccess" -exec echo {} \;
Category(s): Command Line, find, grep, Linux, Server Administration, Web Servers
Tags: , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free