How to create blank index.html file in sub folders

Coffinated
Coffinated used Ask the Experts™
on
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
Comment
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
Commented:
Here's a bash script
#!/bin/bash
find /start/dir -type d | while read dir
do
  [ -f "$dir/index.html" ] || touch "$dir/index.html"
done

Open in new window

Top Expert 2007
Commented:
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 {} \;

Author

Commented:
Tintin:

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