/
Linux tree 명령어 사용법

Linux tree 명령어 사용법

tree 는 폴더의 하위 구조를 계층적으로 표시해 주는 유틸리티로 전체 구조를 대략적으로 파악할 때 유용합니다.

TL;DR

depth 제한

-L(Level) 옵션뒤에 depth 인 2를 주고 실행

$ tree -L 2 -N /
├── usr
│   ├── bin
│   ├── games
│   ├── include
│   ├── lib
│   ├── lib64
│   ├── libexec
│   ├── local
│   ├── sbin
│   ├── share
│   ├── src
│   └── tmp -> ../var/tmp
└── var
    ├── adm
    ├── cache
    ├── crash
    ├── db
    ├── empty
    ├── ftp
    ├── games
    ├── gopher


directory 만 표시

-d 옵션 사용

$ tree -L 2 -d -N /


no indentation + full path

depth 에 따른 들여쓰기를 하지 않을 경우 -i 옵션 추가하고 파일의 전체 경로를 표시할 경우 -f 옵션 사용.

$ tree -L 2 -d -fi -N /
/usr
/usr/bin
/usr/games
/usr/include
/usr/lib
/usr/lib64
/usr/libexec
/usr/local
/usr/sbin
/usr/share
/usr/src
/usr/tmp -> ../var/tmp
/var
/var/adm
/var/cache
/var/crash
/var/db
/var/empty
/var/ftp
/var/games
/var/gopher
/var/kerberos
/var/lib
/var/local
/var/lock -> ../run/lock
/var/log
/var/mail -> spool/mail
/var/nis
/var/opt


2 depth, 특정 폴더 제외

특정 폴더를 제외할 경우 -I(대문자 I) 뒤에 제외할 패턴을 입력. 아래는 tests와 node_moduels 폴더 제외하고 tree 구조 표시

$ tree -N -L 2 -d -I "node_modules|tests"


주요 옵션

optionparam의미
-d
디렉터리만 표시
-f
파일의 전체 경로 표시
-i
 Makes tree not print the indentation lines, useful when used in conjunction with the -f option.
-Ipattern

Do not list those files that match the wild-card pattern.

-PpatternList  only  those files that match the wild-card pattern. 
-Llevel
-N

tree는 ascii 가 아닌 문자는 \332 같이 8진수가 인코딩해서 표시하므로 한글이 깨져 보임.

-N 옵션을 추가하면 한글이 제대로 표시됨.

Ref

Related content

리눅스 스토리지 디바이스 정보를 출력하는 lsblk 명령어 사용법
리눅스 스토리지 디바이스 정보를 출력하는 lsblk 명령어 사용법
More like this
파일 유형(file type)을 알려주는 linux file 명령어 사용법
파일 유형(file type)을 알려주는 linux file 명령어 사용법
More like this
directory 를 생성하는 linux mkdir 명령어 사용법
directory 를 생성하는 linux mkdir 명령어 사용법
More like this
Linux 파일 이름에서 경로와 확장자를 추출하는 법(Extract File Basename Without Path and Extension in Bash)
Linux 파일 이름에서 경로와 확장자를 추출하는 법(Extract File Basename Without Path and Extension in Bash)
More like this
linux cut 명령어 사용법
linux cut 명령어 사용법
More like this
Linux grep 사용법
Linux grep 사용법
More like this