Monthly Archives: January 2014

Documenting directory Trees with tree

I had to document the directory hierarchy of our running servers. It occurred to me to use the 'tree' command to generate a txt fromthe hierarchy tree and that can then be added to our wiki. Plus you can add by hand a brief description for each directory.

The tree command can generate the directory hierarchy from a specific file. It can print to the screen, generate a text file and also can generate an html file.

Example:

/usr
├── bin
├── games
├── include
├── lib
├── lib32
├── local
├── sbin
├── share
└── src

9 directories

To install it with apt:

$ sudo apt-get install tree

To copy the output to a text file you can use the -n option (to deactivate the color special characters) and -o to indicate a file name

$ tree -d -L 1 -n -o fhs.txt /

You can generate html with the -H

$ tree -H -d -L 1 -n -o fhs.html /

You can specify a pattern of files to include with the -P option and also estipulate several searching directories. Don't forget to add the single quotes around the -P pattern to prevent bash to expand it.

$ tree -P '*.list' sources.list.d/ /etc/apt/