Linux Format

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 is a trial lawyer in Delhi. He’s been participat­ing in virtual hearings during the Corona virus pandemic.

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 distributi­ons, or otherwise had to perform a fresh installati­on to keep the system updated. One advantage of this approach was that you got to clean your drives of unnecessar­y muck every so often. This is in sharp contrast to most modern Linux installati­ons, where users are either running a LTS variant, or even a rolling release distributi­on, neither of which necessitat­e frequent reinstalla­tion of the system.

The downside to this system strategy, however, is that your number of directorie­s 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 directorie­s, 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 repositori­es of most popular distributi­ons, installing it is fairly straightfo­rward. 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 functional­ity such as changing directorie­s 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 distributi­on, the br shell function is installed in the ~/.config/broot/launcher/ bash directory and the project will also automatica­lly

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 alternativ­ely run the br command if you want to view another directory. Unlike the tree command, br

doesn’t list the contents of all the directorie­s recursivel­y by default. Instead, many of the directorie­s 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 drasticall­y affect the output generated by Broot:

Flags Purpose

-h show hidden files

-f only show directorie­s

-s show file and directory sizes

-p display permission­s

You can run Broot with each or any combinatio­n 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 combinatio­n. 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 directorie­s, 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 alternativ­es 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 directorie­s 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 automatica­lly open it in the associated applicatio­n. 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 configurin­g your own shortcuts for frequently run commands or operations. If you spend considerab­le time in the terminal, it’s well worth the effort learning the intricacie­s of this nifty utility.

 ??  ?? Split the Broot interface into multiple panels by pressing Ctrl+p. Press Ctrl+right and Ctrl+left arrow keys to switch between the panels.
Split the Broot interface into multiple panels by pressing Ctrl+p. Press Ctrl+right and Ctrl+left arrow keys to switch between the panels.
 ??  ??
 ??  ?? For each command you run, Broot displays the operation it will perform near the bottom of the screen.
For each command you run, Broot displays the operation it will perform near the bottom of the screen.

Newspapers in English

Newspapers from Australia