🌲

tree コマンドまとめ

2025/03/03に公開

tree コマンドとは

ディレクトリやファイルをツリー状に表示するコマンド

コマンドの書式

tree [option] [directory]

コマンド一覧

オプション 概要
-a 隠しファイルを表示 tree -a .
-d ディレクトリのみ表示 tree -d .
-o 出力結果をファイルに保存 tree . -o tree.txt
-L {数字} カレントディレクトリを含む{数字}階層目まで表示 tree -L 2
--noreport ファイルやディレクトリの数のサマリを出力しない。 tree --noreport
tree -I {name} ディレクトリの除外パターン ※ tree -I 'node_modules'

※ 複数指定したい場合は、'node_modules|.git'と繋げる

よく使うコマンド

tree . -a -o filelist.txt -I 'filelist.txt'
  • -a: 隠しファイルも入れる
  • -o filelist.txt: ファイル出力する
  • -I 'filelist.txt': 出力ファイルは除外する

Discussion