Files
tree
Display directories as an indented tree.
Additional Notes
tree recursively lists directory contents in an indented tree format. It is useful for visualizing project structures, exploring nested directories, and documenting folder layouts.
By default, tree prints all directories and files starting from the current directory, with indentation lines showing the hierarchy. The final report shows the total number of files and directories listed.
Syntax
tree [options] [directory...]
Parameters
directory: Path to one or more directories to display. Defaults to the current directory if omitted.
Listing Options
-a: Include hidden files and directories (those starting with.). Never shows.or...-d: List directories only, omit files.-L N: Limit display depth toNlevels.-f: Print the full path prefix for each file.-l: Follow symbolic links to directories.-x: Stay on the current filesystem only (do not cross mount points).-R: Recursively cross down directories, generating00Tree.htmlat each level.-o FILE: Send output to a file.
File Information Options
-p: Print file type and permissions (likels -l).-u: Print username or UID.-g: Print group name or GID.-s: Print file size in bytes.-h: Print file sizes in human-readable format (K, M, G, T, P, E).--si: Like-hbut use SI units (powers of 1000).--du: Report directory sizes accumulated from all contents. Implies-s. Also prints a total in the final report (likedu -c).-D: Print last modification date (or status change time if-cis also used).--timefmt FORMAT: Format the date usingstrftime(3)syntax. Implies-D.-F: Append type indicators likels -F(/for directories,*for executables,@for symlinks,=for sockets,|for FIFOs).--inodes: Print inode numbers.--device: Print device numbers.--acl: Print permissions with+appended if an ACL is present (Linux only). Implies-p.--selinux: Print SELinux context labels (Linux only).-Q: Quote file names in double quotes.-q: Replace non-printable characters with?.-N: Print non-printable characters as-is.
Sorting Options
- *(no flag)*: Sort alphabetically by name (default).
-t: Sort by last modification time.-v: Sort by version number.-c: Sort by last status change time. Also changes-Dto show status change instead of modification time.-U: Do not sort. List files in directory order.-r: Reverse sort order.--dirsfirst: List directories before files.--filesfirst: List files before directories.--sort TYPE: Sort bymtime,ctime,size,version, ornone. Default is alphabetical by name.
Pattern Matching Options
-P PATTERN: List only files matching the wildcard pattern. Supports*,**,?,[...],[^...], and|for alternatives. A trailing/matches only directories.-I PATTERN: Exclude files matching the pattern.--ignore-case: Make-Pand-Icase-insensitive.--matchdirs: Apply-Ppattern to directory names too.--gitignore: Use.gitignorefiles for filtering.--prune: Remove empty directories from output. Useful with-Por-I.--filelimit N: Do not descend directories with more thanNentries.
Output Control Options
--noreport: Suppress the final file/directory count report.-i: Remove indentation lines. Useful with-f. Also minimizes whitespace with-Jor-X.-C: Force color output even when piping.-n: Disable color output.-A: Enable ANSI line graphics.-S: Use CP437 line graphics for console fonts.--charset CHARSET: Set character set for line drawing and HTML.-X: Output as XML.-J: Output as JSON.-H baseHREF: Output as HTML with hyperlinks.-T TITLE: Set the HTML page title.--nolinks: Disable hyperlinks in HTML output.--help: Show full usage information.--version: Show the program version.
Examples
tree
Display the directory tree starting from the current directory.
tree -L 2
Show two levels of nesting only.
tree -a
Include hidden files and directories.
tree -d /etc
Show only the directory structure under /etc.
tree -L 1 -d
List top-level subdirectories only.
tree -h -p /var/log
Show permissions and human-readable sizes.
tree -P "*.sh" --prune
List only shell script files and prune empty directories.
tree -I "node_modules|.git|__pycache__"
Exclude common development directories.
tree -o project-tree.txt
Save the tree to a file.
tree -J
Output the tree as JSON.
tree -C | less -R
View colorized tree output in a pager.
tree --du -h
Show accumulated disk usage per directory.
tree -t -r
Sort by modification time, newest last.
Reading Output
Example output:
.
├── src
│ ├── main.c
│ ├── utils.c
│ └── utils.h
├── Makefile
└── README.md
2 directories, 4 files
The drawing characters indicate:
├──: Intermediate entry in a directory.└──: Last entry in a directory.│: Vertical line connecting deeper levels.- The final line reports the total count of directories and files.
Practical Notes
- Use
tree -L 1 -dfor a quick overview of top-level subdirectories. - Pipe to
less -Rwhen output is long, to preserve colors and scrolling. - Use
-Pand-Iwith--pruneto focus on specific file types. treedoes not follow symlinks by default. Add-lto follow them, but watch for circular links.- The
--duoption can be slow on large trees because it must read every file. - Use
-o FILEto save output for documentation or sharing. - Without
-C, color is usually disabled when piping. Use-Cto force it.