Tech

Why I use the Linux tree command every day – and what it can do for you


Image of bonzai tree.

Jack Wallen/ZDNET

No matter how good the Linux GUI is, I still often use the command line. Part of the reason is habit, but the command line is also very effective. Best of all, when you need real power and flexibility, the command line can’t be beaten.

But what about file managers? It’s hard to beat a good GUI for managing your files. But remember, this is Linux, so for every GUI feature, there’s a command that can do the same thing. For example, tree request.

Also: Two tricks make using the Linux command line a lot easier

Most GUI file managers allow a tree view. This allows you to expand a folder to see the subfolders and files inside without having to navigate inside the root folder first. I prefer this viewing style because it saves me clicks. If you navigate in and out of the file system throughout the day, the fewer clicks you have to make, the more time and effort you’ll save.

The GNOME Files app has tree view enabled.

If you enable Tree View in Gnome Files, you can see what the tree command offers.

Jack Wallen/ZDNET

Now, imagine you’re doing this from the command line and you need to check the contents of folders. If you have a lot of folders and subfolders that you have to go through and look through, you may be using a combination of CD And ls command in a rather inefficient method. You don’t want to have to type and guess so much. Why not simplify that task with the tree command?

Also: New to programming? My 5 favorite Linux tools will get you up to speed faster

The tree command is a tool to recursively list the contents of a directory. The tree adds a bit of color so you immediately know what it is (please note that the color will be affected by the color scheme configured for your terminal window). Use trees
helps you see the layout of folders very simply, so you don’t have to CD in and out or use ls and spend too much time typing when you just need to find a file.

Let me show you how to use the tree easily.

How to install and use the tree

What you need: Not every Linux distribution has the tree command. For example, I found tree installed by default on Fedora but not on Ubuntu. To install the tree, you only need a running Linux instance and a user with sudo privileges.

Open your terminal window and install tree with the command:

sudo apt-get install tree -y

To install tree on a Fedora-based distribution, open a terminal window and issue the command:

To install tree on an Arch-based distribution, open a terminal window and issue the command:

From your terminal window, issue the command:

If you don’t see results printed in color, add the following options:

You’ll see a tree view of the folders and files in the current working directory.

If you create a tree in your home directory, you can see a long list of files and folders at a glance. You can always scroll up to find what you’re looking for, or you can view the contents of a specific folder.

Let’s say you have a large number of files and folders in ~/Music and you want to see the contents of a specific folder (say Rush). To do that, you can issue the command:

The tree command will only print out the hierarchy in the specified directory.

The tree command displays the directory hierarchy.

Here you’ll see how effective tree colors are in helping to differentiate files from folders.

Jack Wallen/ZDNET

There are other options you can use, such as:

  • tree -d – only lists directories
  • tree -f – prints the full path for each file
  • tree -o NAME – send output to a file (where NAME is the name of the file)
  • tree -Q – put all file names in quotes
  • tree -D – print last file modification date

You can read about all the options available for the tree with the command:

Tree makes viewing files and folders on Linux very easy (even without a GUI). I use this tool regularly and highly recommend it as a way to make your work a little more efficient and your files/folders easier to see in your drive’s hierarchy.

News7f

News 7F: Update the world's latest breaking news online of the day, breaking news, politics, society today, international mainstream news .Updated news 24/7: Entertainment, Sports...at the World everyday world. Hot news, images, video clips that are updated quickly and reliably

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button