
No matter how good the Linux GUI is, I often resort to the command line. Part of the reason for this is habit but the command line is also very efficient. On top of that, when you need real power and flexibility, the command line can’t be beat.
But what about the file manager? 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. Take, for instance, the tree command.
Also: Two tricks that make using the Linux command line a lot easier
Most GUI file managers allow for a tree view. This allows you to expand a folder to view the sub-folders and files within without having to first navigate inside the root folder. I prefer this style of viewing because it saves me clicks. If you’re navigating in and out of a file system throughout the day, the fewer clicks you have to make the more time and effort you’ll save.
If you enable Tree view in GNOME Files, you can get an idea of 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 several folders and sub-folders you have to peek in and out of, you could be using a combination of the cd and ls commands in a rather inefficient method. You don’t want to have to do that much typing and guessing. 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 for recursively listing the contents of a folder. Tree adds a dash of color, so you know what’s what at a glance (do note that the colors will be affected by the color palette configured for your terminal window). Using tree
makes it very simple for you to view the layout of directories, so you’re not having to cd in and out or using ls and spending too much time typing, when you only need to locate a file.
Let me show you how easy tree is to use.
How to install and use tree
What you’ll need: Not every Linux distribution includes the tree command. For instance, I’ve found tree installed by default on Fedora but not on Ubuntu. To install tree, you’ll only need a running instance of Linux 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 the terminal window and issue the command:
sudo dnf install tree -y
To install tree on an Arch-based distribution, open the terminal window and issue the command:
sudo pacman -S tree
From your terminal window, issue the command:
If you don’t see the results printed in color, add the option like so:
You should see a tree view of the folders and files in the current working directory.
If you issue tree in your home directory, you might see a long list of files and folders fly by. 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 vast number of files and folders in ~/Music and you want to see the contents of a specific folder (let’s say Rush). For that, you could issue the command:
tree ~/Music/Rush
The tree command will only print out the hierarchy in the folder specified.
Here you see how effective the tree colors can be to help discern files from folders.
Jack Wallen/ZDNET
There are other options you can use, such as:
- tree -d – list only directories
- tree -f – prints the full path for each file
- tree -o NAME – sends the output to a file (where NAME is the name of the file)
- tree -Q – places all file names in double quotes
- tree -D – print the date of the last file modification
You can read about all of the options available to 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 bit more efficient and your files/folders easier to view within the hierarchy of your drive.