tree
ファイルとディレクトリ
書き方
tree -L 2 [path]ディレクトリ構造を字下げした絵として描きます。macOS や軽量な Linux イメージには既定で入っておらず、先に導入が必要です。
よく使うオプション
| オプション | 意味 |
|---|---|
| -L | Limit the depth to N levels |
| -a | Include hidden files |
| -d | Directories only |
| -I | Skip names matching a pattern |
| -f | Print the full path of each entry |
| -h | Show readable sizes |
例
tree -L 2Two levels deep, so the output stays readable.
tree -I 'node_modules|.git'Skips the noisy directories.
tree -d -L 1Just the top-level folders.
移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. tree は何をしますか。
ディレクトリ構造を字下げした絵として描きます。macOS や軽量な Linux イメージには既定で入っておらず、先に導入が必要です。
Q. どう打ちますか。
tree -L 2 [path] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man tree にあります。このコマンドはファイルとディレクトリの仲間です。
関連するコマンド
man ページ: man tree