A quick Bash tip: add an index.html file to a Dropbox public folder

You know that Dropbox is terrific, of course. No? Go and check it out now.

One issue: files in your Public folder have a public URL, that you can send to other people. Unfortunately, directories do not. So how do you share a public directory full of files?

Answer: create an index.html file and share that. Let’s say that your files end in “.txt” and reside in ~/Dropbox/Public/entrez. Do this:

cd ~/Dropbox/Public/entrez
echo "<ol>" > index.html
for i in `ls *.txt`; do echo "<li><a href='$i'>$i</a></li>" >> index.html; done
echo "</ol>" >> index.html

Now you can share the link to the index.html, which when clicked will display a list of links to all the other files in the directory.

3 thoughts on “A quick Bash tip: add an index.html file to a Dropbox public folder

  1. Kamil Slowikowski

    Hi Neil,

    I just want to point out that using `ls` in the for loop is not advised, because filenames that contain spaces will not be handled properly.

    Instead, use an asterisk:
    for i in *; do …

  2. Pingback: BioBits » Blog Archive » Quick Links

Comments are closed.