[手动选题][tech]: 20221208.4 ️ Manage your file system from the Linux terminal.md

This commit is contained in:
六开箱 2022-12-09 01:16:37 +08:00
parent 7ebec9e5ea
commit 857c1814cd

View File

@ -0,0 +1,150 @@
[#]: subject: "Manage your file system from the Linux terminal"
[#]: via: "https://opensource.com/article/22/12/linux-file-manager-nnn"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Manage your file system from the Linux terminal
======
I tend to enjoy lightweight applications. They're good for [low spec computers][1], for [remote shells][2], for the impatient user (OK, I admit, that's me), and for the systems we scrap together to fight the inevitable [zombie apocalypse][3]. 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.][4]
### 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][5] or from the project [Git repository][6].
On macOS, use [Homebrew][7] or [MacPort][8].
### 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][9]) 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.
- 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.
- Press **`2`** to change to a new context.
- 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.
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/12/linux-file-manager-nnn
作者:[Seth Kenlon][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lkxed
[1]: https://opensource.com/article/19/7/how-make-old-computer-useful-again
[2]: https://www.redhat.com/sysadmin/access-remote-systems-ssh
[3]: https://opensource.com/zombie
[4]: https://opensource.com/sites/default/files/2022-10/nnn.filemanager.png
[5]: https://software.opensuse.org//download.html?project=home%3Astig124%3Annn&package=nnn
[6]: https://github.com/jarun/nnn/releases
[7]: https://opensource.com/article/20/6/homebrew-mac
[8]: https://opensource.com/article/20/11/macports
[9]: https://opensource.com/article/19/3/getting-started-vim