yyp٩( 'ω' )و

色々触って遊んでます

treeコマンドが便利な話

まえがき

ディレクトリ構成を書くことがたびたびあるのですが、いちいち記号を探すのが面倒だったのでtreeコマンドを導入しました。

treeインストール

任意のパッケージ管理ツールでインストールします。
今回はMacに入れます。

環境は下記です。

  • OS: macOS Mojave
  • OS version: 10.14.5

brewでインストールします。

brew install tree

インストール終了後、treeを実行すると…

tree                                                                                                                                                                                               [master]
.
├── README.md
├── ansible
│   ├── check-connect-host.md
│   ├── execute-playbook-specific-host.md
│   ├── execute-playbook-specific-task.md
│   ├── show-hosts-list.md
│   ├── step-execute-playbook.md
│   └── use-variable-by-lookup.md
(略)

こんな感じで出てきます。
-Lで表示するディレクトリの深さも指定できます。

tree -L 1                                                                                                                                                                                          [master]
.
├── README.md
├── ansible
├── aws
├── bash
├── git
├── linux
├── mac
├── markdown
├── network
├── nodejs
├── pip
├── terraform
├── vim
├── windows
└── yum

14 directories, 1 file

表示するディレクトリも指定できます。

tree -L 1 ./aws                                                                                                                                                                                    [master]
./aws
└── search-resources-all-region.md

0 directories, 1 file

まとめ

いちいち記号を探す面倒から解放されました…!
環境によってはむやみにパッケージをインストールできないこともあるので、その時に別の環境で実行して記号を探すという使い方もできそうです(あんまりしたくない)