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).

Figure 3: Use the -Q option to save time when copying file names with spaces.

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.

Figure 4: Tree in full flower. From left to right, the information for each file is device ID, UID, GID, file size, and date last modified.

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.

Figure 5: The -r option lists results in reverse alphabetical order.

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.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content