Efficiently manage files with nnn
Tutorial – nnn
If you're a Linux lover, you'll know the command line is the slickest and most efficient way to interact with the system. Free yourself from point-and-click with the nnn command-line file manager.
Popular distros such as Ubuntu have given Linux to the masses with colorful icons and point-and-click interfaces. Still, experienced Linux users can save huge amounts of time and effort by staying within the command-line interface (CLI).
However, the Linux terminal itself doesn't make it easy to navigate quickly between files, plus you need to memorize a string of commands in order to rename, copy, and move files. This is where nnn comes in. If developer jarun's name sounds familiar, it's because he's also the author of ddgr – a CLI for the privacy-centric DuckDuckGo search engine, which we covered in issue 270 [1].
His utility nnn is inspired by an older minimalist file manager for the terminal, noice, from which it derives its rather recursive name (Nnn's Not Noice).
Like ddgr, nnn cuts out the GUI and allows you to perform operations efficiently. To get started, just fire up your regular terminal and run
sudo apt-get install nnn
for Debian-based Linux distros or
sudo dnf install nnn
for RHEL-based distros.
You can now fire up nnn by running nnn
from the command line (Figure 1).
nnn Navigation
Once you fire up nnn, you can start navigating files and folders using the arrow keys. Press right to open a folder and left to return. Alternatively, you can use the same keys as for navigating Vim: H (left), L (right), K (up), and J (down).
When browsing files, simply hit enter in order to open a file within its default app. Out of the box, nnn only has limited support for opening files from within the terminal. You can, however, press e when a text file is highlighted to display contents. (Use :wq
when you're done.)
nnn Names
Once you're comfortable hopping from directory to directory, you may want to perform more advanced file operations.
Press ? to view a complete list of all available commands. (You can also type :wq
here to return to the main window.)
This list can seem overwhelming at first, so start simple. During testing, I downloaded a text file of Shakespeare's Romeo and Juliet, which Project Gutenberg has given the rather unhelpful filename rg1513.txt
.
In order to rename it, I simply navigated to the folder in question, highlighted it, and pressed Ctrl+R. A prompt appeared at the bottom of the window to enter a new filename (e.g., romeoandjuliet.txt)
.
An interesting quirk of nnn is that you can also copy files and folders to a new destination from here. Just press Ctrl+R as if you wanted to rename the file/folder and then press enter (Figure 2). The prompt will now allow you to enter the destination to which you want to copy the file.
nnn Nominations
Although copying individual files can be useful, most often you'll need to move multiple files or even the contents of entire folders.
This is one area where using a file manager such as Nautilus can be much more convenient than entering multiple terminal commands to select individual files.
Luckily, nnn makes the selection process intuitive. In order to select a file or folder, just right-click on the file/folder or press the space bar (Figure 3). You can do this to multiple files within a folder or just press A to select them all. A + icon will appear next to selected files.
If you can't find what you're looking for, use /
to open the prompt, which allows you to filter listings by keyword (Figure 4). You can also use D to toggle detailed file information such as creation date and size.
Buy this article as PDF
(incl. VAT)