Hướng dẫn thử thách
1 / 1
What Is Nano?
When working in the terminal, standard text editors aren't always available, but there are programs designed to edit files directly from within the terminal.
Linux environments typically include a text editor. Vi, or Vim, tend to be the most common. Emacs and Nano may need to be installed manually, but they are readily available for nearly every distribution.
The challenge with Vim is it has a substantial learning curve. If you are not already familiar with it, you may not even know how to close the application! Emacs is arguably a bit more user friendly, but still has its own tome of keyboard shortcuts.
Nano is considerably more streamlined and user-friendly, especially for new learners. It can be much quicker to dive in and edit a file with Nano, and the application even offers on-screen help for the basic keyboard shortcuts.
The tradeoff for this, however, is the lack of extensibility. Unlike Vim or Emacs, which can be extended with plugins to become full development environments, Nano is rather barebones.
Let's take a peek at what Nano can do. To open a file, you can enter `nano <filename>` in the terminal.
Once a file is open, you will see the version of Nano you are running and the name of the file you have open at the top of the screen.
Below that is the content of the file. You can use the <kbd>arrow keys</kbd> to navigate your cursor and insert or delete text with your keyboard. The file will scroll as needed to follow.
Then, at the bottom, you will see a list of available keyboard shortcuts, that looks something like this:
```bash
^G Help ^O Write Out ^F Where Is ^K Cut ^T Execute ^C Location M-U Undo M-A Set Mark M-] To Bracket M-B Previous
^X Exit ^R Read File ^\ Replace ^U Paste ^J Justify ^/ Go To Line M-E Redo M-6 Copy ^B Where Was M-F Next
```
Shortcuts which start with the caret (`^`) symbol indicate you need to hold the <kbd>Ctrl</kbd> key and press the indicated letter. Shortcuts which start with `M-` require you to hold the "meta key", which in most setups should be the <kbd>Alt</kbd> key, and press the letter.
To edit a file in Nano, you only need to know a few of the shortcut commands. After making changes to a file, you can press <kbd>Ctrl</kbd> + <kbd>O</kbd> to "Write Out", or save, the file. After entering the command, you will see the menu at the bottom change to this:
```bash
File Name to write : <filename>
^G Get Help ^T To Files
^C Cancel TAB Complete
```
Press <kbd>Enter</kbd> to save the file and go back to editing the file, or <kbd>Ctrl</kbd> + <kbd>C</kbd> to cancel and go back to editing the file.
While in the editor, you can press <kbd>Ctrl</kbd> + <kbd>X</kbd> to exit Nano and go back to the terminal. If you have unsaved changes when trying to exit, you will see this in the bottom menu:
```bash
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?
Y Yes
^C Cancel N No
```
Press <kbd>Y</kbd> to save your unsaved changes, or <kbd>N</kbd> to discard them.
<table>
<caption>Nano keyboard shortcuts</caption>
<thead>
<tr>
<th scope="col">Action</th>
<th scope="col">Shortcut</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Save the file</th>
<td><kbd>Ctrl</kbd> + <kbd>O</kbd></td>
</tr>
<tr>
<th scope="row">Cancel the current prompt</th>
<td><kbd>Ctrl</kbd> + <kbd>C</kbd></td>
</tr>
<tr>
<th scope="row">Exit Nano</th>
<td><kbd>Ctrl</kbd> + <kbd>X</kbd></td>
</tr>
</tbody>
</table>
With this knowledge, you should be better prepared the next time you need to quickly edit a file on a remote server, where you might not have access to a full graphical environment.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.sh
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵