How to create blank index.html file in sub folders

Coffinated used Ask the Experts™
I need to create a blank index.html in a particular folder and all sub folders. If index.html exists it should not be overwritten, else it needs to be created. All sub folders must be traversed.
Can someone create such script php, shell, perl are fine.

Thank you
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you can do it in batch... And there has to be a silent over-write to replace any index.html with the new one created.

Top Expert 2007
Here's a bash script
find /start/dir -type d | while read dir
  [ -f "$dir/index.html" ] || touch "$dir/index.html"

Open in new window

Top Expert 2007
In fact, you could do the whole thing as a oneliner if you don't mind the modification date of existing index.html being changed

find /start/dir -type d -exec touch {}/index.html {} \;



Thank you for both scripts, I don't mind changing the date if index.html, I like the second script much better.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial