Using find & xargs to create an empty index.html file in every directory

Written by James McDonald

April 21, 2009

If you have global indexing turned on for Apache:

     Options Indexes

You may wish to leave it enabled but still stop indexes being displayed.

Using find and xargs you can create an empty index.html in each directory and Apache will serve it instead of the list of files in the directory thusly:

find -type d | grep -v \.svn | xargs  -I '{}' touch '{}/index.html'

The above command says
find all directories starting from the current directory and below. Pipe the result from find to grep and tell grep to filter out any directorys with .svn in them. Finally use xargs to run touch replacing ‘{}’ with the directory name passed from the grep command so you get touch ./my/dir/path/index.html

To undo:

find ./*/ -name index.html | xargs rm -f

Notice find is given a search path of ./*/ so you don’t delete the index.html from the current directory you generally want an index.html in your web root directory.

1 Comment

  1. Goma

    How do i do this with php? No shell access…


Submit a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

PDF Poster

PDF Poster

Start with a wide long image. This is just a screen shot of my desktop. widescreen.png Convert it to postscript using...