Super User is a question and answer site for computer enthusiasts and power users. 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 want to be able to automatically test all of my servers to make sure that directory browsing is enabled. How do I do this in a shell script?

share|improve this question
up vote 3 down vote accepted

Two suggestions:

  • Create a directory, fetch its contents over HTTP from localhost (using curl, wget -O /dev/stdout, lynx -dump, w3m -dump, elinks -dump) and look for the file list. Example for Apache2, which normally shows Index of /directory:

    cd /srv/http
    mkdir "$name"
    if curl "http://localhost/$name/" | fgrep -qs "Index of /$name"; then
        echo "enabled"
        rmdir "$name"
        echo "disabled"
        rmdir "$name"
        exit 1

    If you are using Lighttpd, nginx or something else, adjust the grep pattern.

  • Alternative: Learn some grep or perl and parse the hell out of your configuration files. The exact process depends on the HTTP daemon you are using – their configuration formats are very different.

share|improve this answer
Nice thanks! Also using curl to get the http response code works for me. 403 means directory listing is disabled, and 200 means it's enabled – David Jun 22 '11 at 8:51

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.