Skip to content


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

If you have global indexing turned on for Apache:

<Directory /blah/>
     Options Indexes
</Directory>

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.

Bookmark and Share

Posted in Linux Tools.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Goma says

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



Some HTML is OK

or, reply to this post via trackback.