TERMINAL: Broot
Shashank Sharma knows it can be tricky to find files and folders, especially when you can’t remember where to look. But now he has a solution…
Shashank Sharma knows it can be tricky to find files and folders, especially when you can’t remember where to look. But now he has a solution…
Back in the 90s and most of the 2000s, Linux users frequently switched distributions, or otherwise had to perform a fresh installation to keep the system updated. One advantage of this approach was that you got to clean your drives of unnecessary muck every so often. This is in sharp contrast to most modern Linux installations, where users are either running a LTS variant, or even a rolling release distribution, neither of which necessitate frequent reinstallation of the system.
The downside to this system strategy, however, is that your number of directories and files keep growing with time. This makes for a messy navigation even if you’re a master organiser.
This is where Broot shines. But before we dive into it, do us a favour and run the tree command real quick. If you’ve never used it before, you might be a little surprised with the vast amount of output the command generates. Put simply, the tree command provides a recursive view of the directory structure on your system. But that’s all it can do. You can’t use it to change directories, or search for files by matching the content within them. With its support for fuzzy search,
Broot can do all that, and can also be used to edit and delete files.
Getting started
Released under the MIT licence, the nifty utility runs on Linux, Mac and even Windows. However, the non-linux variants lack some features and are not as polished. Although not available in the software repositories of most popular distributions, installing it is fairly straightforward. You can download the executable file from the project’s website and place it in a directory that’s in your $PATH:
$ wget -c https://dystroy.org/broot/download/x86_64linux/broot
$ chmod +x broot
$ sudo mv broot /usr/local/bin
Here. we’ve downloaded the script, and used the chmod +x command to make it executable and finally placed it in the /usr/local/bin directory. You’ll now be able to launch Broot with the broot command.
When you run Broot for the first time, the utility checks to see if the br shell function is installed. If not, the project offers to install it. This is essential because although you can launch Broot by invoking the broot
command, some functionality such as changing directories is only available when the utility is launched using br . If you miss the prompt, or chose not to install it, you can run the broot --install command at any point to install the br shell function.
Depending on your distribution, the br shell function is installed in the ~/.config/broot/launcher/ bash directory and the project will also automatically
update your ~/.bashrc file to source this function by adding source /home/linuxlala/.config/broot/ launcher/bash/br to the ~/.bashrc file.
You’ll be presented with a tree overview of the current directory when you run the br . You can alternatively run the br
doesn’t list the contents of all the directories recursively by default. Instead, many of the directories feature a short line underneath informing you of the unlisted content for each of them. This makes for a more easily digestible output.
By default, Broot doesn’t display hidden files, but you can easily fix this by running the br -h command. There are many different such flags that drastically affect the output generated by Broot:
Flags Purpose
-h show hidden files
-f only show directories
-s show file and directory sizes
-p display permissions
You can run Broot with each or any combination of these flags. For a complete list of available flags, run the br --help or the broot --help command.
The arrow keys can be used to navigate through the output generated by Broot. You can view the contents of any given directory by selecting it from the list using the arrow keys and then pressing Enter. If you wish to quit
Broot and switch to a selected directory at the same time, you can do that by pressing Alt+enter key combination. This function is only available when you launch Broot with the br command.
To learn more about how Broot can be used to find files and directories, please refer to the Searching for files and folders box.
Executing commands
With Broot, you can also execute various commands while it’s running to alter the output and even manipulate files. The simplest of these are the alternatives for the flags as discussed above. From within Broot, type :h to toggle viewing hidden files. You can similarly use :files command from within Broot to toggle viewing files or directories only.
Broot refers to these operations as verb commands. For a complete list of available verbs, press ? from within Broot to access the built-in help. In addition to the different flags, you can also perform operations such as delete and move files.
When you press Enter after selecting a file, Broot will automatically open it in the associated application. You can also open files in the configured editor within your shell by selecting a file and then running the :e command. This option only works if the configured editor is equipped to handle the file type.
You can similarly run the :mv command to move files, :rm command to delete files, and so on. Note, however, that Broot’s rm command will perform a rm -rf operation.
There’s quite a bit that you can do with Broot including configuring your own shortcuts for frequently run commands or operations. If you spend considerable time in the terminal, it’s well worth the effort learning the intricacies of this nifty utility.