Manage your file system from the Linux terminal

The nnn file manager on Linux exists in a terminal only, but it feels like a modern keyboard-driven application with intuitive actions and easy navigation.
4 readers like this.

I tend to enjoy lightweight applications. They're good for low spec computers, for remote shells, for the impatient user (OK, I admit, that's me), and for the systems we scrap together to fight the inevitable zombie apocalypse. In my search for a perfect blend of a lightweight application with all the modern conveniences we've learned from experience, I stumbled across a file manager called nnn. The nnn file manager exists in a terminal only, but it feels like a modern keyboard-driven application with intuitive actions and easy navigation.

Image of the nnn file manager.

(Seth Kenlon, CC BY-SA 4.0)

Install nnn

On Linux, you may find nnn in your Linux distribution's software repository. For instance, on Debian:

$ sudo apt install nnn

If your repository doesn't have nnn available, you can download a package for your distribution from OBS or from the project Git repository.

On macOS, use Homebrew or MacPort.

Using nnn

Launch nnn from a terminal:

$ nnn

Your terminal is now the nnn interface, and by default it lists the contents of your current directory:

1 2 3 4 ~

Desktop/
Documents/
Downloads/
Music/
Pictures/
Public/
Templates/
Videos/




4/8 2022-12-01 15:54 drwxr-xr-x 6B

At the top of the nnn interface are tabs (called a "context" in nnn terminology), numbered one to four.

At the bottom of the nnn interface, there are ownership and permission details about your current selection.

Use either the Up and Down arrow keys or the k and j keys (as in Vim) to change your selection. Use the Right arrow key, Return, or the l key to enter a directory or to open a file. Use the Left arrow key or h to back out of a directory.

That's it for navigation. It's easier than any graphical file manager because there aren't any widgets that get in the way. There's no need to Tab over buttons, you just use the arrow keys or the QWERTY home row.

Open a file

One of the reasons you use a file manager is to find a file and then open it. Your desktop already has default applications set, and nnn inherits this knowledge, so press Return or Right arrow to open a file in its default application.

Should you need to open a file in something other than its default application, press = instead, and then type the name of the application in the prompt at the bottom of the nnn interface.

Copy a file

To copy a file or any number of files, you must first select a file to copy, then navigate to its intended destination, and finally invoke the copy command. Thanks to nnn's context control (those are the numbers at the top of the screen, and you can think of them as tabs in a web browser), this is a quick process.

  1. First, select the file you want to copy and press Spacebar to select the file. It's marked with a plus sign (+) to indicate its selected state.

  2. Press 2 to change to a new context.

  3. Navigate to the target directory and press p to copy.

Move a file

Moving files is the same process as copying a file, but the keyboard shortcut for the action is v.

Selecting files

There are a few ways to mark selections in nnn. The first is manual selection. You find a file you want to select, and then press Spacebar to mark it as selected. Press Spacebar again to deselect it.

One selection doesn't cancel another, so you can select several files manually, but that can become tedious. Another way to select many files at once is to "mark in " and "mark out". To mark a selection, press m on the first file you want to select, and then use your arrow keys to move to the last file you want to select. Press m again to close the selection:

1 2 3 4 ~

+Desktop/
+Documents/
+Downloads/
+Music/
+Pictures/
+Public/
Templates/
Videos/




6/8 [ +6 ] 2022-12-01 15:54 drwxr-xr-x 6B

Finally, the third way to select files is to press a to select all. Use A to invert the selection (in this case, to select none.)

Creating an archive

To create an archive of a file or a selection of files, press z. At the bottom of the nnn interface, you're prompted to choose between your current item of your selection. Then you're prompted for a file name. Luckily, nnn is a smart application and derives its file type from the name you provide. If you name your archive example.tar.xz then nnn creates a TAR archive with lzma compression, but if you name it example.zip then it creates a ZIP file.

You can verify the file type yourself by pressing the f key with your new archive selected:

  File: /home/tux/Downloads/example.zip
  Size: 184707          Blocks: 368        IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 17842380    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1002/     tux)   Gid: ( 1002/     tux)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2022-09-20 15:12:09.770187616 +1200
Modify: 2022-09-20 15:12:09.775187704 +1200
Change: 2022-09-20 15:12:09.775187704 +1200
 Birth: 2022-09-20 15:12:09.770187616 +1200
Zip archive data, at least v2.0 to extract
application/zip; charset=binary

Cancel an action

When you find yourself backed into a corner and need to press a panic button, use the Esc key. (This is likely to be the single most confusing keyboard shortcut for a longtime terminal user who's accustomed to Ctrl+C.)

Never close nnn

To quit nnn, press Q at any time.

It's a very capable file manager, with functions for symlinks, FIFO, bookmarks, batch renaming, and more. For a full list of what nnn can do, press the ? key.

The most clever feature is the shell function. Press ! to open a shell over the nnn interface. You'll forget nnn is there, until you type exit and you find yourself back in the nnn interface. It's that easy to leave nnn open all the time, so you can always have quick access to the fastest lightweight file management you're likely to experience.

Tags
Seth Kenlon
Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time.

1 Comment

I never got the hang for nnn, maybe because I'm a long time user of Midnight Commander, which also is an awesome TUI file manager.

I always install it on my servers and desktops.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.