tree

ファイルとディレクトリ

書き方

tree -L 2 [path]

ディレクトリ構造を字下げした絵として描きます。macOS や軽量な Linux イメージには既定で入っておらず、先に導入が必要です。

よく使うオプション

オプション意味
-LLimit the depth to N levels
-aInclude hidden files
-dDirectories only
-ISkip names matching a pattern
-fPrint the full path of each entry
-hShow readable sizes

tree -L 2

Two levels deep, so the output stays readable.

tree -I 'node_modules|.git'

Skips the noisy directories.

tree -d -L 1

Just the top-level folders.

移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. tree は何をしますか。

ディレクトリ構造を字下げした絵として描きます。macOS や軽量な Linux イメージには既定で入っておらず、先に導入が必要です。

Q. どう打ちますか。

tree -L 2 [path] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man tree にあります。このコマンドはファイルとディレクトリの仲間です。

関連するコマンド

man ページ: man tree