# A Review of the nnn File Manager

One of the universal appeal of the command line has to do with the total control a person has with regard with not only his or her environment, but also any tools that run in the background. However, a scary aspect with the terminal for many has to do with file management:

• Typing cd to change directories,
• pwd to get the location report,
• and ls to get all the files and subdirectories,

may prove too much for others. So the need to use a file manager that offers not only shortcuts to these commands, but also added features such as decompression and archiving tools in a single package. Plus, just the layout!

## Introducing the nnn File Manager

Even though I am someone who now has a strong preference for working on the command line, I recently came across a cool tool known as nnn (or $$n^3$$ for short), which is a terminal file manager. You can get it from its homepage, or install it using your distro’s software management solution such as pacman for Arch, apt-get for Debian/ubuntu, dnf install for Fedora, slapt-get for Slackware/Slint, etc.

It falls in the same category as Midnight Commander, Vifm and Ranger. At first, I thought I was just trying it out until I was hooked to it.

the nnn file manager is accessible with the Speakup screen-reader. But when I tried using it with Fenrir, I had a problem, so for the most part I use it with Speakup or Orca when I am using a GUI.

It has got tabbed browsing, which means you can browse more than one directory at a time, with one pane displaying one directory and the other displaying the second directory. In nnn, these tabs are referred to as contexts.

It can display up to four contexts at a time. You move between contexts by just pressing the TAB key or by pressing the number key, from 1 to 4.

## File associations

If you are working in a desktop environment such as Mate, Gnome, KDE or even window tiling managers such as i3, file association takes advantage of the XDGSetting: simply associate a program you like with appropriate files.

For example, when you try to launch a .html file, nnn will open it in your browser.

On the console though, you have to edit a file called nuke, which comes by default in ~/.config/nnn/plugins/ directory.

nuke is just a shell script where you can create a function to handle specific file types and pair them with command line tools.

If you do not want to bother with creating a new function, you can just stick in a switch block inside the hande_extension function. This is what is called when there is no dedicated function to deal with an extension. For instance, below is a snippet from my copy of nuke:

case "${ext}" in ## Archive a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\ rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip) if type atool >/dev/null 2>&1; then atool --list -- "${FPATH}" | eval "$PAGER" exit 0 elif type bsdtar >/dev/null 2>&1; then bsdtar --list --file "${FPATH}" | eval "$PAGER" exit 0 fi exit 1;; rar) if type unrar >/dev/null 2>&1; then ## Avoid password prompt by providing empty password unrar lt -p- -- "${FPATH}" | eval "\$PAGER"
fi
exit 1;;
.....
esac


This block demonstrates how archives are handled.

## Some Keystrokes

nnn comes with a set of keyboard shortcuts that makes your life easier when navigating around. You do not need to memorise them all, as you can just press the ? (the question mark symbol) to get instant help.

Pressing your Down and Up arrow keys moves you around from file to file. If you get to the bottom of the file list, you are going to wrap to the top automatically.

To do the copy and paste operations:

• Navigate to the file or directory which you want to copy;
• Then press the SPACEBAR to mark it;
• You can mark as many files as you like this way. The good part is that you do not need to mark files in one directory: it is possible to navigate from folder to folder and mark all the files you like. nnn will just record all these selections.
• Then go to the destination where you want to paste the files and directories.
• You can press p to copy the files to the destination, otherwise you can just press v to move them to the destination and delete them from the source.

The rename operation is what made me hooked to nnn more than anything else: it supports both standard rename operation and batch renaming.

### Standard rename

To rename a file, (the same thing as the move operation), you press CTRL+r.

A new prompt will pop up. Just start typing in the new name of the file. Otherwise, if you do not want to give a new name, but instead wants to create a copy of a file in the same directory, do the following:

• Press CTRL=r to launch the rename function;
• When prompted to enter a new name, just press the Enter key.
• You will be asked to enter a name for the file copy: just type in a new name such as oldfile-copy.txt and press Enter.
• And you are done!

### Batch Renaming

For any file manager that I work with, this is the feature that I start to look for. I remember my days on Windows, I liked Total Commander’s ability to batch rename. Even these days, I find that Thunar’s Bul Rename tool is a winner.

Anyway, back to nnn, it supports batch renaming if you installed vidir, a vim-like tool for batch renaming.

To use it, just do the following:

• Select all the files you want to rename;
• Press the r key to launch the batch rename utility;
• You will see that a new text file listing all your selected files will be opened.
• For each line, it represents the position of the file in the file list selection pane, so do not change the line numbers in any way: leave them alone.
• For each file you want to rename, just delete the old file name with the dd command and enter the new name.
• Once you are satisfied with the new names as contained in the text file, then save the file with ZZ

### You will see that all your files have got new names.

Isn’t this cool?

By the way, to select all files in a file list pane, just press the letter a. To invert selection, that is to operate on all files that aren’t selected, press uppercase a. And you are done!

## Interesting aliases

finally, let me share with you two of my favourite aliases.

A trick that I often do is to launch nnn with different configurations depending with which environment I am working in.

When I am working on the console, I use the alias n3. This n3 is aliased like this:

alias n3='nnn -cSQ'


This is because the switches to nnn tells it to

• Launch as a command line tool, and not a X-application;
• To record all my contexts in a session file;
• To save position so that I can resume where I left when I relaunch nnn.

Another one is this which I just copied from the nnn manual as it is:

alias ls='nnn -de'


This is when I want to replace the default call to the built-in ls with a call to nnn. However, in my .bashrc file, I did not want to totally replace a call to ls with nnn. So I just used alias l.

## Conclusion

nnn is a file manager that can speed your working on the console. Depending with your needs, you can set it to be your default manager. The only setback I saw with this is that with Orca, when there is only one file or subdirectory, it will not say it out.

Otherwise, nnn is a decent file manager that you can try out.

## Footnotes:

1

That’s capital z twice!