Efficiently manage files with nnn

Tutorial – nnn

Article from Issue 272/2023
Author(s):

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).

Figure 1: By default, nnn will open to your current running directory (in this case the home folder), unless you specify the PATH variable.

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.

Figure 2: To copy a file, press Ctrl+R, then enter without renaming. You can then type the new path.

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.

Figure 3: Use the space bar or right-click to select individual files. Alternatively, just press A to select all the files in a folder.

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.

Figure 4: Use / to filter files in a particular folder by keyword. Press Esc to cancel and return to normal navigation.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Sunflower

    Following in the footsteps of Norton Commander and its clones, the Sunflower twin-panel file manager takes a giant leap forward with a switch to Python 3 and GTK3.

  • Sunflower File Manager

    Sunflower is a highly configurable graphical file manager with two windows that implement an unusual concept by trying to integrate the command line with the file manager.

  • Micro

    Editing text at the command line doesn't have to be daunting. Micro brings the ease and intuitiveness of a graphical editor to the Linux terminal.

  • Xfce

    The Xfce desktop travels light but still comes with all the essential features.

  • imgp

    In no time at all, imgp can change the resolution of images, as well as convert files from PNG to JPEG, remove metadata, and rotate images.

comments powered by Disqus