LoginSignup
1
2

More than 5 years have passed since last update.

Macのtreeコマンドでindex.html的なものを作る

Last updated at Posted at 2016-09-09

ディレクトリ内に index.html なものを生成したい。
サブディレクトリには不要なので、ルートだけに tree.html が欲しい。
具体的には、Jenkinsのビルド成果物を Amazon S3 にアップロードするときに使いたい。
tree コマンドが使えそう。

結論から

treeコマンドの -H baseHREF Prints out HTML format with baseHREF as top directory. というオプションを使う。

実行結果

-Hオプション無しで実行
$ tree
結果
.
├── nya.html
└── subdir
    └── neko.html

1 directory, 2 files

-H の baseHREF に.を指定してみる

-Hオプション付きで実行
$ tree -H .
結果
<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <meta name="Author" content="Made by 'tree'">
 <meta name="GENERATOR" content="$Version: $ tree v1.7.0 (c) 1996 - 2014 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro $">
 <title>Directory Tree</title>
 <style type="text/css">
  <!-- 
  BODY { font-family : ariel, monospace, sans-serif; }
  P { font-weight: normal; font-family : ariel, monospace, sans-serif; color: black; background-color: transparent;}
  B { font-weight: normal; color: black; background-color: transparent;}
  A:visited { font-weight : normal; text-decoration : none; background-color : transparent; margin : 0px 0px 0px 0px; padding : 0px 0px 0px 0px; display: inline; }
  A:link    { font-weight : normal; text-decoration : none; margin : 0px 0px 0px 0px; padding : 0px 0px 0px 0px; display: inline; }
  A:hover   { color : #000000; font-weight : normal; text-decoration : underline; background-color : yellow; margin : 0px 0px 0px 0px; padding : 0px 0px 0px 0px; display: inline; }
  A:active  { color : #000000; font-weight: normal; background-color : transparent; margin : 0px 0px 0px 0px; padding : 0px 0px 0px 0px; display: inline; }
  .VERSION { font-size: small; font-family : arial, sans-serif; }
  .NORM  { color: black;  background-color: transparent;}
  .FIFO  { color: purple; background-color: transparent;}
  .CHAR  { color: yellow; background-color: transparent;}
  .DIR   { color: blue;   background-color: transparent;}
  .BLOCK { color: yellow; background-color: transparent;}
  .LINK  { color: aqua;   background-color: transparent;}
  .SOCK  { color: fuchsia;background-color: transparent;}
  .EXEC  { color: green;  background-color: transparent;}
  -->
 </style>
</head>
<body>
    <h1>Directory Tree</h1><p>
    <a href=".">.</a><br>
    ├── <a href="./nya.html">nya.html</a><br>
    └── <a href="./subdir/">subdir</a><br>
    &nbsp;&nbsp;&nbsp; └── <a href="./subdir/neko.html">neko.html</a><br>
    <br><br>
    </p>
    <p>

1 directory, 2 files
    <br><br>
    </p>
    <hr>
    <p class="VERSION">
         tree v1.7.0 © 1996 - 2014 by Steve Baker and Thomas Moore <br>
         HTML output hacked and copyleft © 1998 by Francesc Rocher <br>
         JSON output hacked and copyleft © 2014 by Florian Sesser <br>
         Charsets / OS/2 support © 2001 by Kyosuke Tokoro
    </p>
</body>
</html>

ほぼ、期待するものが出来上がった!

環境

  • OS X Elcapitan (10.11.3)
  • tree v1.7.0

おまけ

直下のサブディレクトリ内に tree.html を作ってまわるワンライナー

$ find . -maxdepth 1 -type d -exec tree {} -H . -o {}/tree.html \;
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2