Search notes:

Shell command: tree

Show content of directories in a tree like format (indented etc).

Some interesting command line options

Listing options

-d Only show directories
-D Show last modification
-a Also show hidden files (similar to ls -a)
-L depth Limit depth of printed directory tree to depth.
-P pattern List only files that match pattern.
-I pattern Ignore (don't show) files that match pattern.
--ignore-case Ignore case for pattern in -P and -I.
--matchdirs Apply pattern specified with -P to directories also.
--prune Prune empty directories (for example when used with -P and -I)
--filelimit n Do not descend into directories that contain more than n files.
-l Follow symbolic links (but void recursion)
-x Don't cross file system boundaries (Similar to find -xdev)
--timefmt fmt
-o filename Write output to filename.
--charset cs
--noreport Do not write summary after printing the tree (the line that reads something like 138 directories, 2107 files)
-f Print full path prefix for each file. See also -i and this this example.

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 per ls -l), see this example.
-u Print the file's username (or UID if no username is available). See this example.
-g Print the file's group name (or GID if no group name is available).
-s Print the size of each file (bytes). See also --du.
-h Print the size of each file human readably (same idea as also ls -h). See also --si.
--si Like -h but use SI units.
--du Print directory sizes plus accumulated sizes of directories and files beneath it (like du -c). Implies -s
-D Print the date of the last modification time or if -c is used, the last status change time for the file listed.
-F Append a / for directories, a = for socket files, a * for executable files, a > for doors (Solaris) and a | for FIFO's (Same idea as ls -F).
--inodes Prints the inode number of the file or directory
--device Prints the device number to which the file or directory belongs

Sorting options

-v Sort the output by version. Similar to ls -v
-t Sort the output by last modification time instead of alphabetically.
-c Sort the output by last status change instead of alphabetically. Modifies the -D option (if used) to print the last status change instead of modification time.
--sort[=]type Sort the output by type instead of name. Possible values are: ctime (-c), mtime (-t), size or version (-v).
-U Do not sort. Lists files in directory order. Disables --dirsfirst.
-r Sort the output in reverse order. This is a meta-sort that alter the above sorts. This option is disabled when -U is used.
--dirsfirst List directories before files. This is a meta-sort that alters the above sorts. This option is disabled when -U is used.

Graphic options

-i Don't indent output, useful in conjunction with -f. Also removes as much whitespace as possible when used with -J or -x. See this example.
-A Turn on ANSI line graphics hack when printing the indentation lines.
-S Turn on CP437 line graphics (useful when using Linux console mode fonts), equivalent to --charset=IBM437 and may eventually be depreciated.
-n Turn colorization off always, over-ridden by the -C option.
-C Turn colorization on always, using built-in color defaults if the LS_COLORS or TREE_COLORS environment variables are not set. Useful to colorize output to a pipe.

ML/JSON/HTML options

-X Emit output in XML format.
-J Emit output in JSON format.
-H baseHREF Emit output in HTML format (including HTML references). baseHREF gives the base ftp location when using HTML output. For colors via CSS style-sheet, the -C option must be added.
-T title Sets the <title> and <h1> header string in HTML output mode.
--nolinks Turns off hyperlinks in HTML output.

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.

Misc options

--help Outputs a verbose usage listing.
--version Outputs the version of tree.
-- Option processing terminator. No further options will be processed after this.

Print directory tree file file permissions

Using -p (print permission) and -u (print username) prints a directory tree along with files' and directories' permissions and ownership:
$ tree -pu /home/rene
This command can be modifed to include -i and -f so that the file names are not indented but rather printed with path elements:
$ tree -pufi /home/rene

Installing tree

On systems with apt (Debian, Ubuntu…), tree can be installed like so:
sudo apt-get install tree

Links

https://github.com/ReneNyffenegger/shell-commands/tree/master/tree

See also

The cmd.exe utility tree.com
Shell commands

Index