Home | Legal Tech | Projects | Writings

Index File

If you've ever struggled your way around a data room, you'll know a navigable index page is a lifesaver. This simple Linux command, which should come by default in your distro will create a list of all the files in your data room and create a file with links to open them.

Tasklist

  1. Learn the tree command.
  2. Navigate to the bible folder in our terminal
  3. Run the tree command and output it to an html file.

1. The tree command

This is a program that usually comes bundled with Linux, which is simple to run. Like many commands, it is run with additional input flags. To learn what these inputs are, we simply ask the program which flags it takes by checking the manual page.

Generally when using a bash terminal, to find out information on a progam, enter the name into the terminal preceded by man.

Therefore, to read the manual for the tree command you should enter:

$ man tree

The output looks complex at first, but it's really rather simple. Start by reading the description, then scroll down to see the options.

tree man page

The flags you see can be added to the end of the tree command to give it additional instructions, in this case like creating a file with html links. You can see that to add links (i.e. output to HTML), we need to use tree -H. Since we also want colors, we'll throw in -C.

Now that we have our command - tree -H -C - we should navigate to the bible directory before we run it, as the index will start from the folder you are in unless you specify otherwise (to find out how to specify otherwise, check the man page!

2. Navigating to the bible folder

We're going to take the opportunity to learn how to navigate to a certain folder in the terminal using the cd (change directory) command.

To move between folders in the terminal we use the cd command (change directory). To go to a directory, enter cd and then the path to that directory. To go back (or 'up') a directory, use two dots, e.g.:

$ cd ..

Another good thing to know is that ~ always refers to your 'home' directory. So no matter where I start from within my files, I can use the tilde to start my path from the home folder. E.g. if I have a folder named 'Pictures' in my home folder, this command will always take me there:

$ cd ~/Pictures

Without the tilde (~), cd Pictures will look in the directory you are already in, so will only work when already in the home folder.

Let's put our bible into 'home/bible'. We can create the folder by entering:

$ mkdir ~/bible

Now that the folder is made, you may drag and drop the files in using the normal graphical interface that you know and love. Or if you are feeling clever, try the mv command, followed by the name of your source folder and then your destination. If your bible folder was called 'dealdocuments' you could move them to our new 'bible' folder with:

$ mv dealdocuments ~/bible)

Finally, enter the folder with:

$ cd ~/bible

3. Run the tree command

We're sitting in our folder, and we have our command! However, if we run the command as is, we'll just see the output spat out into the terminal, which isn't much use. The final part of the puzzle is to output the results of the command into an html file.

The beauty of Linux (actually the broader family of related operating systems called "UNIX") is that it is philosophically predicated on the idea that each program should do one thing neatly and well, so that lots of different programs can be combined together for super-flexibility. This means that bash is designed to ensure that the output of programs can be easily put into the input of another (known as 'piping') or spat out into files (known as 'redirecting'). To spit out into files, we use the > symbol.

In our case, we want our final file to be an html file, which we'll call 'bibleindex.html'. That makes our final command:

$ tree -C -H > bibleindex.html

Once you've run the above command, you'll see the index file in your bible folder. Open it and try out the links! Here's some dummy folders and files to give you an example ofhow the output looks:

example tree output

Because we created an HTML file (i.e. a website) we can open it up in our web browser like Firefox or Chrome. Each of the links are clickable to open the documents directly. How handy.