Skip to content

Instantly share code, notes, and snippets.

@gentam
Created May 1, 2017 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gentam/42bee765753fd8e9be4b8fb8277c7c55 to your computer and use it in GitHub Desktop.
Save gentam/42bee765753fd8e9be4b8fb8277c7c55 to your computer and use it in GitHub Desktop.
print files and directories tree in HTML list
#!/usr/bin/env bash
echo "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\">\
<title>Directory Tree</title></head><body>"
find . \
| tail -n +2 | sed -e '/\/\./d' \
| awk -F/ '
BEGIN { preNF = 0 }
{
if (NF > preNF) print "<ul>"
if (NF < preNF) {
diff = preNF - NF
while (diff--) print "</ul>"
}
printf "<li><a href=\"%s\">%s</a></li>\n", $0, $NF
preNF = NF
}
END { while (--preNF) print "</ul>" }'
echo "</body></html>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment