Seeing the forest with tree
File Output Options
Tree
gives you the choice of substituting non-printable characters in results with a question mark (-q
) or printing them as is (-N
). You also have the option of printing file names with double-quotation marks around them (-Q
), which can be convenient if a file name uses spaces and you plan to copy and paste it for use in another command (Figure 3).
Colorblind users might also prefer to include -F
in the command, to print symbols to identify file types – for example, /
for directories.
However, most of tree
's file output options display meta-information. With -u
, tree
prints the user ID (UIF), and -g
prints the group ID (GID), as shown in Figure 4. If your interest is in file sizes, then -s
prints them in bytes, and -h
shows them in the most suitable unit readable for humans: K
specifying kilobytes, M
for megabytes, G
for gigabytes, and so on.

You can also include in the output the disk usage for each directory with -du
or show the device number for each result with --device
.
Sorting Options
The sorting options are probably what distinguishes tree
most from ls
. The default is alphabetical order, but if you suspect a file or directory might be at the bottom of the alphabet, -r
will list results in reverse alphabetical order instead (Figure 5). Similarly, --dirfirst
can save you time by listing all the directories first if you are reasonably sure that what you are looking for is a directory.
Other handy sorting options include last modification time (-t
) and last status change (-c
). However, the option most likely to interest developers is version (-v
), which can help locate a particular generation of a file.
« Previous 1 2 3 Next »
Buy this article as PDF
Pages: 4
(incl. VAT)