Seeing the forest with tree

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.

The Next Generation

The ls command existed in the first version of Unix [3]. It remains a core command, and tree is not immediately obvious as an enhanced, next generation replacement.

However, the minor advantages of tree start to add up. In particular, its ability to exclude large portions of the directory structure and its extra sorting abilities make it slightly quicker for finding most files and directories.

Additionally, its visual representation of drives should not be underestimated. By desktop standards, tree's representation of files and directories is primitive. Yet the tree is how people are taught to think about files and directories, and to see your mental representation on the screen only makes interacting with tree easier.

The advantage of tree is not great in any single case. However, the more you do file management at the command prompt, the more tree's advantages mount. Take the time to learn it, and you might decide that ls has had its day.

For more information, check out the extensive examples of how to use tree from Barracuda Firewall  [4].

The Author

Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest coast art. You can read more of his work at http://brucebyfield.wordpress.com

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

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

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Ncdu

    Ncdu adds some GUI-like features to the classic du command.

  • Colorful lsd

    A revamp of ls, lsd offers color coding plus revised options relevant to the modern computer.

  • Workspace: TreeLine

    The hybrid nature of TreeLine means it offers more than your typical information manager. An outliner as well as a database, it allows you to sort and store all kinds of data with ease.

  • New Commands for Old Purposes

    As the standard core Linux commands have become more complex due to revisions, new commands have risen to take their place. Bruce looks at seven of these modern commands, plus a terminal emulator.

  • Housecleaning

    This month, Mike Schilli writes a quick terminal UI in Go to help track down space hogs on his hard disk.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News