A command-line file manager

Nimble Tree Climber

© Photo by Kev Kindred on Unsplash

© Photo by Kev Kindred on Unsplash

Author(s):

The broot file manager guarantees clearer, quicker navigation of the directory tree at the command line.

You most likely use a file manager daily to do a variety of tasks from navigating the filesystem to creating, deleting, moving, and copying files. File managers come in many shapes and sizes, from command-line-only tools to the many Norton Commander clones (e.g., Midnight Commander) to graphical tools such as Dolphin (KDE), Nautilus (Gnome), Thunar (Xfce), or PCManFM (LXDE). In particular, if you have ever had to work with Windows Explorer, you will probably appreciate a good file manager.

Amongst the plethora of file managers, broot (pronounced "be root") clearly stands out from the competition in terms of functionality. Broot, an interactive file manager for the command line written in Rust, offers an innovative concept. It replaces commands such as ls and tree with an interactive display.

Copied from tree

Broot is maintained on GitHub [1] and works on Linux, Raspberry Pi OS, macOS, and Windows. Even in very large directories, this nimble file manager provides the user with a better and quicker overview. In principle, broot's display is based on the output from the tree command (Figure 1). However, broot displays the directory tree in a more compact way and makes the display interactive, in contrast to tree. You can search broot's tree display at lightning speed using fzf [2], a fuzzy search tool.

Figure 1: While broot only partially expands large directories, it tells you how many files or directories are unlisted in the current tree view.

Setup

In addition to the GitHub repo, the developers maintain a project website that also provides instructions for broot's installation [3] and configuration. On this site, you also will find binary packages for Android, Linux, Linux with musl, Raspberry Pi, and Windows 10.

You can also find broot in the package archives of Alpine Linux, Arch Linux, Manjaro, Solus, Void Linux, and the BSD derivatives NetBSD and FreeBSD. However, be warned that some of these versions are partially outdated [4]. For distributions with deb package management, a third-party repository offers broot along with other interesting applications [5]. There is also a deb package available without a repository [6], but you must handle the updates manually if you go this route. This deb package works for testing purposes and removes the need to integrate the key for third-party repositories, a feature that Debian recently made less user-friendly [7].

For a permanent installation, I advise building broot yourself from source (Listing 1). To do this, you need a Rust development environment [8], which will give you the latest version. Broot stores its configuration in your home directory in ~/.config/broot/conf.hjson; see the website [3] for a detailed description.

Listing 1

Building broot

$ git clone https://github.com/Canop/broot.git
$ cargo install --path .

Retrofit

When you first launch broot, it asks if it can retrofit the br shell function (Figure 2). You will want to allow this since it lets you use the cd command to change directories inside broot. In the future, you can simply start broot with the br command, followed by the path of the directory you want to view. If you save the path specification, the tool displays the contents of the current working directory.

Figure 2: On the first launch after installation, broot asks if you agree to set up broot as a shell function. Enter Y to agree to this.

While inspired by the tree command, there are some differences. If you compare the output of tree and broot side by side, you will notice that broot displays the same directory more compactly because it doesn't open all the directories immediately (Figure 3). You can navigate the tree at the keyboard and then press Enter to open a directory. In many terminals, you can also double-click to do this. To go back, press Esc.

Figure 3: One look at the respective scrollbars for tree (left) and broot (right) highlights the difference between the two commands.

Standard View

To open a view of the directory tree, you use:

br -dp

which is similar to ls -la. However, broot supports interactive operation, as well as searching in directories and direct actions against the files and folders. If you want to keep this (or some other) view as the default, define it in the config file under ~/.config/broot/conf.hjson by removing the comment sign in front of default flags and entering the desired view.

While you are in the config file, you might want to adjust the color output to suit your preferences under skins. Broot can theoretically also display file type icons [9], but I was unable to configure this; instead, empty rectangles appeared rather than icons.

The config file's location follows XDG convention, which is dependent on your system settings. The fastest way to find the configuration file is to type a question mark in broot's search field, which launches a help screen. From the help screen, you can then open the file in your system's editor by typing os (for open_stay).

By default, broot uses two panels (Figure 4), but you can increase the number in the configuration file. You can open an additional panel by pressing Ctrl+Right arrow. If you want to open a file and exit broot at the same time, you can do this by pressing Alt+Enter. Otherwise, select Ctrl+Q to exit broot when you are finished.

Figure 4: Broot lets you use multiple panels side by side. You can copy files back and forth between panels using cpp.

Using arguments, you can add desired attributes to the view at startup. For example, br -h toggles hidden files, while br -gi toggles .gitignore files that would normally be hidden. Broot clarifies the status of these two attributes with a y or n in the search field bottom right. For both of these arguments, you can use br -d to see the date of the last change.

To find out which files and folders are taking up the most space, you can use "whale spotting" mode (br -w) to get a list of files sorted by size; broot visualizes the size ratios as a bar chart in a similar way to ncdu or GDU (Figure 5).

Figure 5: The --whale-spotting (-w) option shows which files or folders are resource hogs.

Fuzzy Search

The search field, located bottom left, is one of broot's strengths. Directly above the search, a status bar indicates what an entered command does or if an argument is incorrect, as appropriate.

You can use broot's fuzzy search capability to find files, even if you've forgotten the exact file name. For example, if you are unsure about how to spell "LinuxUser" but know that it contains the three letters l, x, and u in that order (sequential, but not necessarily consecutive order), broot can find all of the files whose names contained those three letters in that specific order (Figure 6).

Figure 6: Broot's ability to use a fuzzy search helps you to find files or directories whose names or spellings you have forgotten.

If you introduce the search term with a slash, you can also use regular expressions. A question mark entered in the search field calls the built-in help, which offers a subset of the detailed documentation found under the Usage tab on the website [10].

If you want to run a search on very large or very slow disks, it may be necessary to enable :total_search or press Ctrl+S to ensure that broot searches the entire disk.

To exit broot but first change to a directory in the shell beforehand using cd, navigate to the desired directory and press Alt+Enter. If you apply the same key combination to a file, broot again exits and opens the file with the associated application. Speaking of shells: Alongside Bash or Dash, broot also works well with Z shell and Fish.

Verbs

You can also use the search field to enter verbs, which the developers explain on the website under Usage | Verbs & Commands [11]. These verbs are actually Linux commands that you can execute directly in broot. To list all the available verbs, enter a question mark in the search field. In addition, you can also define verbs yourself in the broot configuration file.

The search field has two modes: input mode and command mode. Use command mode to find content. If you want to use verbs here, you must enter a space or a colon as a prefix followed by the verb and, where needed, an argument. For example, to open a file in your favorite editor, navigate to the file and type Space+E or Shift+.+E in the search field.

The frequently-used commands mv, cp, rm, and mkdir are available as verbs. In addition, d shows the last change date, pe lists the ownership, ss sorts directories and files by size, and h unearths hidden files. For directories managed by Git, gf displays the number of changed or new files at the top of a status line, while gs maps the git status command. You can also combine searches with commands. Navigate to a file by typing a letter and then, without removing the search term with Esc, delete the file with :rm.

If you work with panels, you can also use the cpp (copy to panel) verb; it supports copying from one panel to the other. For example, exporting directory trees with the pt (print tree) command exports the directory tree to the shell. You also can modify the command in the configuration file to export to a specific directory. To start broot in a monochrome look and without decoration, type broot --no-style.

Conclusions

Broot is one of the most useful command-line tools I have come across in quite some time. The documentation on the website turns out to be just as excellent as broot itself. Study the documentation more closely, and you'll find that there is much more to discover than this article can cover.

Broot can speed up filesystem navigation and replace commands such as tree and ls. You can display low-resolution images in a panel (Figure 7); if you use Kitty [12] terminal emulation, you can even view high-resolution images. By the way, when I used Kitty, the icons also worked.

Figure 7: Broot even opens images, but in low resolution. If you use the Kitty terminal emulator, you get high-resolution images because it harnesses the GPU for rendering.

If you do most of your work at the command line, you will quickly warm to broot. With a flat learning curve, the benefits in terms of clarity and work speed are substantial. If you have shied away from the command line thus far, you might even want to rethink your relationship with it thanks to broot.