Linux users: These text-based file managers are overlooked gems

Linux users: These text-based file managers are overlooked gems

[ad_1]

Terminal-based file managers may seem a little old school, but these two options for Linux will come in handy for a variety of tasks.

istock-542928596.jpg

Image: iStock/Spectral-Design

Terminal-based file managers may seem like relics of ancient times, but even in this age of touchscreens, nothing can handle hundreds of files more efficiently. Besides, a terminal may still be your only option to work on remote servers or recover your files after a system crash. 

Two file managers for Linux that deserve more coverage are nnn and ranger. These file managers are made for terminals, but they’re also usable with a mouse and available as binary packages for most Linux distributions.

SEE: Linux file and directory management commands (TechRepublic Premium)

File manager nnn goes everywhere you go

It’s hard to be more compact and ubiquitous than nnn. It needs just 4 MB of memory and eight colors to run on Linux, macOS, BSD, Haiku, Cygwin, WSL, Raspberry Pi and Android via Termux, with basic support for screen readers and braille displays.

Figure A

imagea.jpg

The nnn interface, showing contexts (top) and bookmark keys (bottom).

The nnn interface (Figure A) works great on small devices, having a single column that by default only shows the names of files and folders and can also display images when running in some terminals (Figure B). You can work in up to four folders simultaneously by opening each of them in a separate “context” (i.e., tab), and see size and timestamps of files by pressing the “d” key or starting nnn with the -d switch. Another switch, -S, makes nnn sort folders and files by size.

It is possible to save the full configuration of an nnn session by typing “s” twice, and reload it by typing “sl” or launching nnn with the “-s SESSION_NAME” switch.

Figure B

imageb.jpg

nnn may even show image previews, but only with some terminals (for details, see the website).

To start working with nnn, you just need a few keys: “h” goes up one level, “j” and “k” scroll down and up the files list, respectively, “l” opens a folder. Press “e” to edit text files in place with Vim, “~” to return to your home directory, “-” to the last visited, and “?” to see the active keyboard shortcuts.

There are two ways to search for files, toggled by the “/” key. Type it once, and nnn will display only entries that match what you type afterward, as you type it. Typing “/” again activates regular expressions, allowing you to type “.linux.” to find all the files or folders that contain the “linux” string.

Moving, deleting or copying files is delegated to the shell. Press “!” to spawn a shell in the current folder, and then execute any command or script you want. When done, nnn will resume working from where you left it.

One really intriguing feature of nnn is that it puts the file you select in the $nnn environment variable, where every script you launch from a spawned shell may find it. You can also write your own script to extend nnn.

Bookmarks must be set outside the program into an environment variable. For example, this shell command tells nnn to open the folder /home/photo whenever the user presses “b” for “bookmark” and then “f”.

export NNN_BMS='f:/home/photo/;w:/home/marco/files/archive/work'

This is not an exception. Every nnn parameter is set in the same way, instead of writing it into one configuration file. Therefore, the easiest way to have a permanent nnn configuration is to set all its variables in your shell configuration file, following this example in the Arch Linux wiki.

SEE: Linux 101: What tech pros need to know (TechRepublic Premium)

File manager ranger is flexible and highly configurable

By default, ranger has three interlinked panes, which always show the parent directory, the current one and a preview of its contents (Figure C). Ranger also has a multipane mode (Figure D) with side-by-side, independent panes, as well as multiple, numbered tabs, accessible by pressing the Alt key and their number.

Figure C

imagec.jpg

The three connected panes of the ranger file manager.

Figure D

imaged.jpg

Ranger in multipane mode.

Regardless of the layout, typing “:flat N” shows all the files in the current folder and all its subfolders up to the Nth level as one list. This can be extremely useful in some cases and really confusing in others. To return to flat listing, type “:flat 0”.

Ranger adopts many Vim key bindings, besides the same, basic navigation keys of nnn. For example, “yy” and “pp” copy and paste files, respectively. Even command calls work in the same way: You type a colon and then their name.

If you dislike Vim, no problem–you can control ranger even with emacs-like bindings. To do it, add this line in your shell configuration file:

export RANGER_LOAD_DEFAULT_RC=FALSE

and copy the rc_emacs.conf file that comes with ranger in your ~/.config/ranger folder.

Ranger handles bookmarks better than nnn. To bookmark the current folder, type “m”, followed by the letter or digit of your choice. This lets you jump to that folder from any location by simply typing a backtick, followed by that same character. Two backticks bring you back to the previous folder you visited.

Learning how to use ranger is easier than it seems. Type “?” followed by “m”, “k”, “c”, or “s” to see the man page, keyboard shortcuts, built-in commands and your current configuration, respectively.

To customize how ranger works, you can place in your ~/.config/ranger folder up to four files, starting with the already mentioned rc.conf for basic configuration. Custom Python commands following these guidelines go into commands.py.

Figure E

imagee.jpg

Previewing PDF files inside ranger.

Scope.sh is the configurable shell script that ranger runs to preview files (Figure E), but it works as intended only if you have all the third-party utilities it calls (e.g., odt2txt to render OpenDocument files).

The last way to customize ranger actually configures its “file opener” that is called rifle and can also handle images (Figure F); this is a separate tool, usable even without ranger, that guesses which program should open, instead of just previewing, a given file.

Figure F

imagee.jpg

Even ranger may show image previews (see website for details).

Will you use these file managers?

Even though both nnn and ranger suffer the same problem–that is, internal preview of images works only on some “non-mainstream” terminals–both file managers are very useful programs. Do you plan to run nnn, ranger or both? Let us know in the article comments.

Also see

[ad_2]

Source link

Leave a Reply

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