treeShow a directory hierarchy as a tree
tree draws a directory and everything under it as an indented tree, with counts at the end. It's the fastest way to understand an unfamiliar project, a Helm chart or a config directory, and to paste a layout into a ticket or README.
tree [-adfhiLpugJ] [-L LEVEL] [-I PATTERN] [-P PATTERN] [DIRECTORY...]You've cloned or SSHed into an unfamiliar service and want its layout at a glance.
treeList contents recursively as a tree. Not installed by default on Ubuntu Server: sudo apt install tree.
tree reads each directory with the same getdents() system call ls uses, sorts the entries (alphabetically by default, with --dirsfirst or -t to change that) and recurses into subdirectories depth-first, drawing the branch lines with box-drawing characters. It stats entries to know which are directories and, with -p, -u, -g, -h or -D, to print the inode details in brackets. It doesn't follow symlinks to directories unless you pass -l, which avoids loops. Options like -L, -d, -I and -P only change what is printed or descended into. At the end it prints how many directories and files it showed (the starting directory counts as one). With -J or -X it emits JSON or XML instead, which scripts can parse.
-L NDescend at most N levels-aShow hidden files (names starting with .)-dDirectories only-I PATTERNExclude names matching the pattern ('node_modules|.git')-P PATTERN --pruneShow only files matching the pattern, drop empty branches-h / --duHuman-readable sizes / directory sizes summed up-p -u -gShow permissions, owner and group of each entry-f -iFull paths, no indentation lines (a find-like list)--dirsfirstList directories before files-FAppend / to directories, * to executables, @ to symlinks-JOutput JSONtree in / or in a repository with node_modulesIt prints every file in the hierarchy: hundreds of thousands of lines that flood the terminal.
tree -L 2, tree -d, or tree -I 'node_modules|.git'tree -I node_modules|.gitUnquoted, the shell treats | as a pipe and tries to run .git as a command.
tree -I 'node_modules|.git'Reading tree --du sizes as disk usagetree sums apparent file sizes; disk usage depends on block allocation and sparse files.
du -sh dir for real disk usageTry these on a Linux machine of your own. Each task has a hint and a solution.
Show the structure of ~/app two levels deep, including hidden files.
Show only the directories under ~/data.
Show where all .txt files are under ~/data, hiding branches with no .txt files.
List ~/app/src with permissions, owner and sizes in a human-readable form.
treeShow a directory hierarchy as a tree
tree draws a directory and everything under it as an indented tree, with counts at the end. It's the fastest way to understand an unfamiliar project, a Helm chart or a config directory, and to paste a layout into a ticket or README.
tree [-adfhiLpugJ] [-L LEVEL] [-I PATTERN] [-P PATTERN] [DIRECTORY...]You've cloned or SSHed into an unfamiliar service and want its layout at a glance.
treeList contents recursively as a tree. Not installed by default on Ubuntu Server: sudo apt install tree.
tree reads each directory with the same getdents() system call ls uses, sorts the entries (alphabetically by default, with --dirsfirst or -t to change that) and recurses into subdirectories depth-first, drawing the branch lines with box-drawing characters. It stats entries to know which are directories and, with -p, -u, -g, -h or -D, to print the inode details in brackets. It doesn't follow symlinks to directories unless you pass -l, which avoids loops. Options like -L, -d, -I and -P only change what is printed or descended into. At the end it prints how many directories and files it showed (the starting directory counts as one). With -J or -X it emits JSON or XML instead, which scripts can parse.
-L NDescend at most N levels-aShow hidden files (names starting with .)-dDirectories only-I PATTERNExclude names matching the pattern ('node_modules|.git')-P PATTERN --pruneShow only files matching the pattern, drop empty branches-h / --duHuman-readable sizes / directory sizes summed up-p -u -gShow permissions, owner and group of each entry-f -iFull paths, no indentation lines (a find-like list)--dirsfirstList directories before files-FAppend / to directories, * to executables, @ to symlinks-JOutput JSONtree in / or in a repository with node_modulesIt prints every file in the hierarchy: hundreds of thousands of lines that flood the terminal.
tree -L 2, tree -d, or tree -I 'node_modules|.git'tree -I node_modules|.gitUnquoted, the shell treats | as a pipe and tries to run .git as a command.
tree -I 'node_modules|.git'Reading tree --du sizes as disk usagetree sums apparent file sizes; disk usage depends on block allocation and sparse files.
du -sh dir for real disk usageTry these on a Linux machine of your own. Each task has a hint and a solution.
Show the structure of ~/app two levels deep, including hidden files.
Show only the directories under ~/data.
Show where all .txt files are under ~/data, hiding branches with no .txt files.
List ~/app/src with permissions, owner and sizes in a human-readable form.