TREE(1)
๐ณ TREE(1) โ General Commands Manual ๐ณ
okay bestie, this is part 1 of 2, and we're covering tree(1) from the General Commands Manual โ the recursive directory-listing icon itself. It's giving filesystem realness, and we're gonna get you all the way together ๐
โจ
๐ธ NAME ๐ธ
tree โ list contents of directories in a tree-like format. That's the whole gig, and it's iconic ๐ซถ
โจ SYNOPSIS โจ
tree [-acdfghilnpqrstuvxACDFJQNSUX] [-L level [-R]] [-H [-]baseHREF] [-T
title] [-o filename] [-P pattern] [-I pattern] [--gitignore]
[--gitfile[=]file] [--matchdirs] [--metafirst] [--ignore-case]
[--nolinks] [--hintro[=]file] [--houtro[=]file] [--inodes] [--device]
[--sort[=]name] [--dirsfirst] [--filesfirst] [--filelimit[=]#] [--si]
[--du] [--prune] [--charset[=]X] [--timefmt[=]format] [--fromfile]
[--fromtabfile] [--fflinks] [--info] [--infofile[=]file] [--noreport]
[--hyperlink] [--scheme[=]schema] [--authority[=]hostname] [--opt-
toggle] [--acl] [--selinux] [--condense] [--compress[=]#] [--version]
[--help] [--] [directory ...]
๐ DESCRIPTION ๐
So tree is a recursive directory listing program, and what it does is produce a depth-indented listing of files. It gets colorized ala dircolors if the LS_COLORS environment variable is set and output is to a tty. Lowkey obsessed with that detail ๐
With no arguments, tree lists the files in the current directory. When directory arguments are given, tree lists all the files and/or directories found in the given directories, each in turn. Upon completion of listing all files/directories found, tree returns the total number of files and/or directories listed. Periodt.
By default, when a symbolic link is encountered, the path that the symbolic link refers to is printed after the name of the link in the format:
name -> real-path
If the -l option is given and the symbolic link refers to an actual directory, then tree will follow the path of the symbolic link as if it were a real directory. Bestie, that's the follow-the-link behavior, no cap ๐ฆ
๐ OPTIONS ๐
Tree understands the following command line switches:
๐ฆ LISTING OPTIONS ๐ฆ
-aโ All files are printed. By defaulttreedoes not print hidden files (those beginning with a dot.). In no event doestreeprint the file system constructs.(current directory) and..(previous directory). Not today, dot-dot ๐-dโ List directories only.-lโ Follows symbolic links if they point to directories, as if they were directories. Symbolic links that will result in recursion are avoided when detected. Safety first, bestie ๐ซถ-fโ Prints the full path prefix for each file.-xโ Stay on the current file-system only. Alafind -xdev.-Llevelโ Max display depth of the directory tree.-Rโ Recursively cross down the tree each level directories (see-Loption), and at each level outputting to a file named00Tree.html(ala-o).-Ppatternโ List only those files that match the wild-card pattern. You may have multiple-Poptions. Note: you must use the-aoption to also consider those files beginning with a dot.for matching. Valid wildcard operators are:*โ any zero or more characters**โ any zero or more characters as well as null/'s, i.e./**/may match a single/?โ any single character[...]โ any single character listed between brackets (optional-(dash) for character range may be used: ex:[A-Z])[^...]โ any single character not listed in brackets|โ separates alternate patterns
A / at the end of the pattern matches directories, but not files. Slash at the end means directory energy ๐
-Ipatternโ Do not list those files or directories that match the wild-card pattern. You may have multiple-Ioptions. See-Pabove for information on wildcard patterns.--gitignoreโ Uses git.gitignorefiles for filtering files and directories. Also attempts to walk up the directory tree from the given path(s) searching for.gitignorefiles as it goes, stopping at/or a directory containing a.gitdirectory. If a.gitdirectory is found it will add the.git/info/excludefile as well. Also uses$GIT_DIR/info/excludeif present. Git girlies rise ๐ง--gitfile[=]fileโ Usefileexplicitly as a gitignore file.--ignore-caseโ If a match pattern is specified by the-Por-Ioption, this will cause the pattern to match without regard to the case of each letter.--matchdirsโ If a match pattern is specified by the-Poption, this will cause the pattern to be applied to directory names (in addition to filenames). In the event of a match on the directory name, matching is disabled for the directory's contents. If the--pruneoption is used, empty folders that match the pattern will not be pruned. Directory-name matching said not today to its contents ๐ญ--metafirstโ Print the meta-data information at the beginning of the line rather than after the indentation lines.--pruneโ Makestreeprune empty directories from the output, useful when used in conjunction with-Por-I. See BUGS AND NOTES below for more information on this option.--infoโ Prints file comments found in.infofiles. See .INFO FILES below for more information on the format of.infofiles.--infofile[=]fileโ Usefileexplicitly as a info file.--noreportโ Omits printing of the file and directory report at the end of the tree listing.--charset[=]charsetโ Set the character set to use when outputting HTML and for line drawing.--filelimit[=]# โ Do not descend directories that contain more than#entries.--condenseโ Condenses the output of directory 'singletons' โ directories that themselves only contain a single directory โ onto a single line and does so recursively. Note that any meta-information printed will be for the first directory shown. Singleton directories got condensed, and honestly? Slay.-ofilenameโ Send output tofilename.
๐ FILE OPTIONS ๐
-qโ Print non-printable characters in filenames as question marks instead of the default.-Nโ Print non-printable characters as is instead of as escaped octal numbers.-Qโ Quote the names of files in double quotes.-pโ Print the file type and permissions for each file (as perls -l).-uโ Print the username, or UID # if no username is available, of the file.-gโ Print the group name, or GID # if no group name is available, of the file.-sโ Print the size of each file in bytes along with the name.-hโ Print the size of each file but in a more human readable way, e.g. appending a size letter for kilobytes (K), megabytes (M), gigabytes (G), terabytes (T), petabytes (P) and exabytes (E). Human-readable sizes are highkey the move ๐--siโ Like-hbut use SI units (powers of 1000) instead.--duโ For each directory report its size as the accumulation of sizes of all its files and sub-directories (and their files, and so on). The total amount of used space is also given in the final report (like thedu -ccommand.) This option requirestreeto read the entire directory tree before emitting it, see BUGS AND NOTES below. Implies-s. Big du energy, but make it tree-shaped ๐ฅ-Dโ Print the date of the last modification time or if-cis used, the last status change time for the file listed.--timefmt[=]formatโ Prints (implies-D) and formats the date according to the format string which usesstrftime(3)syntax.-Fโ Append a/for directories, a=for socket files, a*for executable files, a>for doors (Solaris) and a|for FIFO's, as perls -F.--inodesโ Prints the inode number of the file or directory.--deviceโ Prints the device number to which the file or directory belongs.--acl(Linux only) โ Prints the permissions, and if an ACL is present on the file appends+to the list of permissions. Implies the-poption.--selinux(Linux only) โ Prints the SELinux label for a file if one is present for it.
๐ SORTING OPTIONS ๐
-vโ Sort the output by version.-tโ Sort the output by last modification time instead of alphabetically.-cโ Sort the output by last status change instead of alphabetically. Modifies the-Doption (if used) to print the last status change instead of modification time.-Uโ Do not sort. Lists files in directory order. Disables--dirsfirst.-rโ Sort the output in reverse order. This is a meta-sort that alters the above sorts. This option is disabled when-Uis used.--dirsfirstโ List directories before files. This is a meta-sort that alters the above sorts. This option is disabled when-Uis used.--filesfirstโ List files before directories. This is a meta-sort that alters the above sorts. This option is disabled when-Uis used.--sort[=]typeโ Sort the output by type instead of name. Possible values are:ctime(-c),mtime(-t),size,version(-v) ornone(-U).
๐จ GRAPHICS OPTIONS ๐จ
-iโ Makestreenot print the indentation lines, useful when used in conjunction with the-foption. Also removes as much whitespace as possible when used with the-Jor-Xoptions.-Aโ Turn on ANSI line graphics hack when printing the indentation lines. This option is now equivalent to--charset=ANSI.-Sโ Turn on CP437 line graphics (useful when using Linux console mode fonts). This option is now equivalent to--charset=IBM437and may eventually be depreciated.-nโ Turn colorization off always, over-ridden by the-Coption, however overridesCLICOLOR_FORCEif present.-Cโ Turn colorization on always, using built-in color defaults if theLS_COLORSorTREE_COLORSenvironment variables are not set. Useful to colorize output to a pipe. Color to a pipe? Iconic behavior, honestly ๐--compress[=]# โ Compresses the indentation lines. The argument may be a positive number from 1 (normal) to 3 (a single character) or -1 to -3 which removes the additional space at each indentation level. Greater compression levels turn off indentation lines (i.e.-i).
โจ XML/JSON/HTML/HYPERLINKS OPTIONS โจ
-Xโ turns on XML output, bestie. Your directory tree becomes an XML formatted file. so structured. much wow. ๐ฆ-Jโ turns on JSON output. Your directory tree becomes a JSON formatted array. for the jq girlies ๐-H [-]baseHREFโ turns on HTML output, including HTTP references. genuinely so useful for ftp sites.baseHREFgives the base ftp location when you're using HTML output โ like, your local directory might be/local/ftp/pub, but it has to be referenced asftp://hostname.organization.domain/pub. sobaseHREFshould beftp://hostname.organization.domain. ifbaseHREFbegins with a dash (-), then the dash is removed and it indicates that tree should remove the first directory name from the href URL. โจ
Hint (from the manpage, not me): don't use ANSI lines with this option, and don't give more than one directory in the directory list. If you wish to use colors via CSS style-sheet, use the -C option in addition to this option to force color output. ๐
--hintro[=]fileโ uses file as the HTML intro in place of the default one. Use an empty file or/dev/nullto eliminate the intro altogether. bye intro ๐--houtro[=]fileโ uses file as the HTML outro in place of the default one. Use an empty file or/dev/nullto eliminate the outro altogether. bye outro ๐-T titleโ sets the title and the H1 header string in HTML output mode. main character energy for your tree fr fr ๐--nolinksโ turns off hyperlinks in HTML output. no links, no problem ๐ซถ--hyperlinkโ enables OSC 8 terminal hyperlinks for terminals that support them. see BUGS AND NOTES below ๐--scheme[=]schemaโ sets the schema used in the OSC 8 hyperlinks. the default schema is'file://'. if the schema omits the colon (:), then://will be appended to the schema. thoughtful of it ๐--authority[=]hostname|authorityโ sets the authority (hostname) to use for the OSC 8 hyperlinks. by default, the local hostname of the machine as returned bygethostname()is used as the authority. a dot (.) or a set of""'s, sans=, (i.e. the empty string) can be used to indicate a null authority. poetic honestly ๐ธ
๐ INPUT OPTIONS ๐
--fromfileโ reads a directory listing from a file rather than the file-system. paths provided on the command line are files to read from rather than directories to search. the dot (.) directory indicates that tree should read paths from standard input. ๐ญ
NOTE: this is only suitable for reading the output of a program such asfind, nottree -fi, as symlinks are not distinguished from files that simply contain' -> 'as part of the filename โ unless the--fflinksoption is used. okay that's actually important, don't skip it ๐
--fromtabfileโ like--fromfile, tree reads a directory tree from a text file where the files are tab indented in a tree like format to indicate the directory nesting level. tab indentation is the whole vibe here ๐--fflinksโ processes symbolic link information found in a file, as from the output of'tree -fi --noreport'. only the first occurrence of the string' -> 'is used to denote the separation of the filename from the link. first one only, periodt โจ
๐ง MISC OPTIONS ๐ง
--opt-toggleโ enables option "toggling". turns on the ability to toggle options such as-a,-h, etc. useful to add to an alias when you wish to disable options enabled in the alias. iconic little uno-reverse feature tbh ๐ฅ--helpโ outputs a verbose usage listing. help bestie ๐ซถ--versionโ outputs the version of tree. ๐--โ option processing terminator. no further options will be processed after this. that's it, that's the line, we're done here ๐ช
๐ .INFO FILES ๐
.info files are similar to .gitignore files, if a .info file is found while scanning a directory it is read and added to a stack of .info information. noted. stacked. archived. ๐
Each file is composed of comments (lines starting with hash marks (#),) or wild-card patterns which may match a file relative to the directory the .info file is found in.
If a file should match a pattern, the tab indented comment that follows the pattern is used as the file comment. a comment is terminated by a non-tab indented line. multiple patterns, each to a line, may share the same comment. so efficient of them โจ
๐ธ FILES ๐ธ
/etc/DIR_COLORSโ System color database.~/.dircolorsโ Users color database..gitignoreโ Git exclusion file$GIT_DIR/info/excludeโ Global git file exclusion list.infoโ File comment file/usr/share/finfo/global_infoโ Global file comment file
๐ฆ ENVIRONMENT ๐ฆ
LS_COLORSโ Color information created bydircolorsTREE_COLORSโ Uses this for color information overLS_COLORSif it is set.TREE_CHARSETโ Character set for tree to use in HTML mode.CLICOLORโ Enables colorization even ifTREE_COLORSorLS_COLORSis not set.CLICOLOR_FORCEโ Always enables colorization (effectively-C)NO_COLORโ Disable colorization (effectively-n) (seehttps://no-color.org/)LC_CTYPEโ Locale for filename output.LC_TIMEโ Locale for timefmt output, seestrftime(3).TZโ Timezone for timefmt output, seestrftime(3).STDDATA_FDโ Enable the stddata feature, optionally set descriptor to use.
๐ AUTHOR ๐
- Steve Baker (
Steve.Baker.llc@gmail.com) - HTML output hacked by Francesc Rocher (
rocher@econ.udg.es) - Charsets and OS/2 support by Kyosuke Tokoro (
NBG01720@nifty.ne.jp)
legends, all of them ๐ซถ
๐ BUGS AND NOTES ๐
okay bestie, this is the section where we get real. no cap, read it.
- Tree does not prune "empty" directories when the
-Pand-Ioptions are used by default. use the--pruneoption. ๐ - The
-hand--sioptions round to the nearest whole number unlike thelsimplementations which rounds up always. different math, same vibe ๐ญ - Pruning files and directories with the
-I,-Pand--filelimitoptions will lead to incorrect file/directory count reports. the numbers will lie to you, and that's just how it is ๐ - The
--pruneand--duoptions cause tree to accumulate the entire tree in memory before emitting it. for large directory trees this can cause a significant delay in output and the use of large amounts of memory. so like, be careful with your giant monorepo, she's hungry ๐ - The timefmt expansion buffer is limited to a ridiculously large 255 characters. output of time strings longer than this will be undefined, but are guaranteed to not exceed 255 characters. undefined behaviour, my beloved ๐
- XML/JSON trees are not colored, which is a bit of a shame. the
jqutility can colorize the JSON however, just not the filenames by file-type alaLS_COLORS. we mourn ๐ง๏ธ - OSC 8 hyperlinks may be poorly supported by your terminal. for my version of Konsole it is necessary to set the schema to
file:(no//) and use a null authority. it may also be necessary to spend 3.5 hours finding the option to turn on hyperlinks. 3.5 hours. real. ๐ฅ - Probably more. ๐
And also, as of version 2.0.0, in Linux, tree will attempt to automatically output a compact JSON tree on file descriptor 3 (what I call stddata,) if present and the environment variable STDDATA_FD is defined or set to a positive non-zero file descriptor value to use to output on. it is hoped that some day a better Linux/Unix shell may take advantage of this feature, though BSON would probably be a better format for this. manifesting that for them โจ
โญ SEE ALSO โญ
dircolors(1), ls(1), find(1), du(1), jq(1), strftime(3), gitignore(5)
go read those too, i believe in you ๐ง
okay that's the whole page, bestie ๐ you made it to the end, and honestly? slay. this was Tree 2.3.2 โ theTREE(1)manual page, officially complete. now go runtreeon something and feel something. bye bye ๐ โจ๐
๐ฆ where this page comes from
- alpine 3.24: tree-doc 2.3.2-r0 ยท GPL-2.0-or-later
- arch rolling: tree 2.3.2-1 ยท GPL-2.0-or-later
- nixpkgs unstable: tree 2.3.2
- Copyright (c) 1996 - 2026 by Steve Baker
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms