Linux/Linux Shell Command

tree - 디렉터리 및 파일을 트리 형식으로 출력

드로니뚜벅이 2022. 5. 1. 22:01

특정 디렉토리의 하위 구조를 계층적인 구조로 확인하고 싶을 때 "tree" 명령어를 사용합니다.
명령어가 존재하지 않을 경우 설치해 줍니다.

$ tree --version
zsh: command not found: tree
$ sudo apt install tree
$ tree --version
tree v1.8.0 (snap) (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro

형식: tree [옵션]

Option Param Description
-a   All files are listed (including hidden files/directories)
-d   List directory only
-f   Prints the full path prefix for each file
-i   Makes tree not print the indentation lines, useful when used in conjunction with the -f option
-l pattern Do not list those files that match the wild-card pattern
-L level  
-p pattern List only those files that match the wild-card pattern.

사용 예

$ tree -L 2

$ tree -L 2 -d

 

[error opening dir]

간혹 특정 폴더에서 tree 명령어를 입력하면 오류가 발생하는 경우가 있습니다. snap 의 문제일 수도 있다고 하는데 잘 모르겠습니다만 그런 경우에는 이전 버전을 삭제하신 후 apt로 다시 설치하시고 쉘을 다시 실행해 주시면 정상동작합니다.

$ tree /etc
/etc [error opening dir]

$ sudo snap remove tree
$ rm -rf $HOME/tree
$ sudo apt install tree
$ exec -l $SHELL
$ exit # restart your shell