1,105,594 Community Members

Create index.html in all directories

Member Avatar
diocode
Newbie Poster
1 post since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm looking for a command or bash script that will create an index.html file in every directory and subdirectory starting at the current directory. I would like it to prompt to overwrite so I don't delete a good index.html file.

Member Avatar
L7Sqr
Veteran Poster
1,006 posts since Feb 2011
Reputation Points: 179 [?]
Q&As Helped to Solve: 168 [?]
Skill Endorsements: 11 [?]
 
0
 
$ export INDEXFILE=/path/to/index/file/index.html
$ find . -type d -exec cp -i ${INDEXFILE} '{}' \;

That copies ${INDEXFILE} interactively to every directory found below the execution point.

N.B. Not tested.

Member Avatar
cfajohnson
Junior Poster
199 posts since Dec 2008
Reputation Points: 10 [?]
Q&As Helped to Solve: 24 [?]
Skill Endorsements: 0 [?]
 
0
 

This doesn't prompt to overwrite; it does nothing in directories already containing index.html:

ndx=index.html
find . -type d | while read dir
do
  (
    cd "$dir" &&
     [ -s "$ndx" ] || mkindex > "$ndx" ## where mkindex is a script to create index file
  )
done
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: