We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,571 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Create index.html in all directories

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.

3
Contributors
2
Replies
6 Days
Discussion Span
1 Year Ago
Last Updated
3
Views
diocode
Newbie Poster
1 post since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

L7Sqr
Practically a Posting Shark
866 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7

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
cfajohnson
Junior Poster
196 posts since Dec 2008
Reputation Points: 25
Solved Threads: 23
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0699 seconds using 2.64MB