title: generating a directory listing as webserver index page in linux
body: <p>I am using </p>
  
  <pre><code>python -m SimpleHTTPServer 8080
  </code></pre>
  
  <p>to start a webserver from a linux directory. I am trying to write a shell script that generates a index.html page containing the following information :
  File Name( as a hyperlink ), File Size, Last Modified Date. So really a custom directory listing.</p>
  
  <p>Here is the script which currently gets the correct info but displays all of it on a single line and doesn't hyperlink the filename. Can anyone direct me into the right direction?</p>
  
  <pre><code>    TITLE="Latest Logs"
      echo "&lt;html&gt;" &gt; index.html
      echo "&lt;title&gt;$TITLE&lt;/title&gt;" &gt;&gt; index.html
      echo "&lt;body&gt;" &gt;&gt; index.html
      echo "&lt;h1&gt;$TITLE&lt;/h1&gt;" &gt;&gt; index.html
      ls -ctgGh | awk '{print $3 " " $4 " " $5 " " $6 " " $7}' \
      | grep -v index.html \
      | sed 's/[^0-9\s]+[.][^0-9\s]+/&lt;a href="&amp;"&gt;&amp;&lt;\/a&gt;&lt;br\/&gt;/g' \
      &gt;&gt; index.html
      echo "&lt;/body&gt;&lt;/html&gt;" &gt;&gt; index.html
  </code></pre>
  
  <p>So what i am piping into sed is :</p>
  
  <blockquote>
    <p>374,Nov 6,04:03,generate.sh<br/>
    7.5M,Nov 6,04:00,Admin-server.log<br/>
    46M,Nov 6,03:48,run1.log<br/>
    528K,Nov 4,15:03,build.log<br/></p>
  </blockquote>
  
  <p>and i want to get :</p>
  
  <pre><code>375,Nov 6,04:14,&lt;a href=generate.sh&gt;generate.sh&lt;/a&gt;
  7.5M,Nov 6,04:09,&lt;a href=Admin-Server.log&gt;Admin-Server.log&lt;/a&gt;
  46M,Nov 6,03:48,&lt;a href=run1.log&gt;run1.log&lt;/a&gt;
  528K,Nov 4,15:03,&lt;a href=build.log&gt;build.log&lt;/a&gt;
  </code></pre>