Bus errorとSegmentation faultに困ったら見るブログ

物理の研究者による日々の研究生活のメモ書きです ( python/emacs/html/Japascript/シェルスクリプト/TeX/Mac/C言語/Linux/git/tmux/R/ポケモンGO)

【シェルコマンド】tree状にファイル構造を表示してくれるコマンド

lsだとファイルの名前が表示されるだけだが、それを各階層で見やすく整形してくれるtreeコマンドというのがある
Macだとデフォルトで入っていないので、portで入れる

sudo port install tree
使い方は
tree ./
とかでOK

たとえば

% tree ./Matrix/
./Matrix/
├── Matrixlib.o
├── makefile
├── testMatrix
├── testMatrix.c
└── testMatrix.o

0 directories, 5 files



色々とオプションが用意されている

-Iオプションで、該当するファイルを除外する

% tree ./Matrix/ -I "*.[o]"
./Matrix/
├── makefile
├── testMatrix
└── testMatrix.c
■ -Pオプションで該当するファイルだけを表示する
% tree ./Matrix/ -P "test*"
./Matrix/
├── testMatrix
├── testMatrix.c
└── testMatrix.o
■ -dオプションで、ディレクトリのみを表示する

-aオプションで、隠しファイルも表示される

-Lオプションで、何階層まで表示するかを選べる



おまけ

findコマンドを使ってtreeみたいなことをしてみる・・・
■ 参考 : treeを使わずにfindでディレクトリツリーリスト表示

% find ./Matrix | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\(
[^ ]\)/|-\1/"

-Matrix
-makefile
-Matrixlib.o
-testMatrix
-testMatrix.c
-testMatrix.o