linux nano命令_Nano入门指南,Linux命令行文本编辑器

linux nano命令

linux nano命令

banner

New to the Linux command-line? Confused by all of the other advanced text editors? How-To Geek’s got your back with this tutorial to Nano, a simple text-editor that’s very newbie-friendly.

Linux命令行的新手? 是否与所有其他高级文本编辑器混淆? How-To Geek帮助您学习Nano的本教程,Nano是一个非常简单的文本编辑器,非常适合新手。

When getting used to the command-line, Linux novices are often put off by other, more advanced text editors such as vim and emacs. While they are excellent programs, they do have a bit of a learning curve. Enter Nano, an easy-to-use text editor that proves itself versatile and simple. Nano is installed by default in Ubuntu and many other Linux distros and works well in conjunction with sudo, which is why we love it so much.

当习惯了命令行时,Linux新手通常会被其他更高级的文本编辑器(例如vim和emacs)推迟使用。 尽管它们是优秀的程序,但它们确实有一些学习曲线。 输入Nano,这是一个易于使用的文本编辑器,它证明了自己的多功能和简单。 Nano默认安装在Ubuntu和许多其他Linux发行版中,并且可以与sudo一起很好地工作,这就是为什么我们如此喜欢它的原因。

运行纳米 (Running Nano)

01 command run

You can run nano in two ways. To open nano with an empty buffer, just type in “nano” at the command prompt.

您可以通过两种方式运行nano。 要使用空缓冲区打开nano,只需在命令提示符下键入“ nano”。

You can also use the following syntax:

您还可以使用以下语法:

nano /path/to/filename

纳米/ path / to /文件名

Nano will follow the path and open that file if it exists. If it does not exist, it’ll start a new buffer with that filename in that directory.

Nano将遵循该路径并打开该文件(如果存在)。 如果不存在,它将在该目录中使用该文件名启动一个新缓冲区。

Let’s take a look at the default nano screen.

让我们看一下默认的纳米屏幕。

02 default screen

At the top, you’ll see the name of the program and version number, the name of the file you’re editing, and whether the file has been modified since it was last saved. If you have a new file that isn’t saved yet, you’ll see “New Buffer.” Next, you’ll see the contents of your document, a body of text. The third-line from the bottom is a “system message” line that displays information relevant to the program executing a function. Here, you can see that it says “New File.” Lastly, the final two rows at the bottom are what make this program very user-friendly: the shortcut lines.

在顶部,您将看到程序的名称和版本号,正在编辑的文件的名称,以及该文件自上次保存以来是否已被修改。 如果您有一个尚未保存的新文件,则会看到“新缓冲区”。 接下来,您将看到文档内容,即文本正文。 底部的第三行是“系统消息”行,显示与执行功能的程序有关的信息。 在这里,您可以看到它显示为“新文件”。 最后,底部的最后两行是使此程序非常人性化的内容:快捷方式行。

It’s a WYSIWYG editor; “what you see is what you get.” What you type directly goes into the text input, unless you modify it with a key like Control or Meta. It’s pretty simple, so type some text out, or copy something and paste it into your terminal so we have something to play with.

它是所见即所得的编辑器; “你所看到的就是你得到的。” 除非使用Control或Meta这样的键对其进行修改,否则您直接输入的内容将直接输入到文本输入中。 这很简单,所以输入一些文本,或者复制一些内容并将其粘贴到您的终端中,这样我们就可以玩一些东西了。

03 text to work with

捷径 (Shortcuts)

Program functions are referred to as “shortcuts” in nano, such as saving, quitting, justifying, etc. The most common ones are listed at the bottom of the screen, but there are many more that aren’t. Note that nano does not use the Shift key in shortcuts. All shortcuts use lowercase letters and unmodified number keys, so Ctrl+G is NOT Ctrl+Shift+G.

程序功能在nano中被称为“快捷方式”,例如保存,退出,对齐等。最常见的功能在屏幕底部列出,但还有许多其他功能。 请注意,nano不使用快捷键中的Shift键。 所有快捷方式均使用小写字母和未修改的数字键,因此Ctrl + G不是Ctrl + Shift + G。

Hit Ctrl+G to bring up the Help documentation and scroll down to see a list of valid shortcuts.

按Ctrl + G打开帮助文档,然后向下滚动以查看有效快捷方式的列表。

04 help

When you’re done looking at the list, hit Ctrl+X to exit help.

查看完列表后,请按Ctrl + X退出帮助。

Let’s say you’re working on a new text file, or “buffer,” and you want to save it. This is called “writing out” and is executed by hitting Ctrl+O. You’ll be prompted for a filename to use, and the shortcuts at the bottom will change to reflect what you can enter to complete this particular command.

假设您正在处理一个新的文本文件或“缓冲区”,并且想要保存它。 这称为“写出”,是通过按Ctrl + O执行的。 系统将提示您输入要使用的文件名,底部的快捷方式将更改以反映您可以输入以完成此特定命令的内容。

05 write-out file

If you want to insert the contents of another file into your current buffer, you’d type Ctrl+R.

如果要将另一个文件的内容插入当前缓冲区,请键入Ctrl + R。

06 file to insert from

You can cancel both of the previous commands by typing Ctrl+C.

您可以通过键入Ctrl + C取消前面的两个命令。

You can hit Escape twice instead of holding down the Control key, if you have trouble doing that. There are also some commands that require use of the Meta key. On most keyboard layouts, Meta equates to the Alt button.

如果您在执行此操作时遇到困难,则可以按两次Escape键而不是按住Control键。 还有一些命令需要使用Meta键。 在大多数键盘布局上,Meta等同于Alt键。

When you want to quit nano, you just hit Ctrl+X. Nano will politely ask you if you want to save your buffer, and you can cancel this action as well.

当您要退出nano时,只需按Ctrl + X。 Nano会礼貌地询问您是否要保存缓冲区,也可以取消此操作。

14 exiting

导航 (Navigation)

Now that we’ve got a hang of shortcuts, let’s get used to moving around a text file very quickly. Of course, you can always use the Home, End, Page Up, Page Down, and the arrow keys to get around, but that requires moving your fingers from the letters that we all love so much.

现在,我们有了许多捷径,让我们习惯于非常快速地在文本文件中移动。 当然,您始终可以使用Home键,End键,Page Up键,Page Down键和箭头键来四处走动,但这需要将手指移离我们都非常喜欢的字母。

To move the cursor forward or backward, you can type Ctrl+F and Ctrl+B. To move up and down one line at a time, you can type Ctrl+P and Ctrl+N. In other words, you can use those keys instead of the Right, Left, Up, and Down arrows, respectively. Missing the Home and End keys? You can use Ctrl+A and Ctrl+E. Want to move pages at a time instead? Ctrl+V moves down a page, and Ctrl+Y moves up a page.

要向前或向后移动光标,可以键入Ctrl + F和Ctrl + B。 要一次上下移动一行,可以键入Ctrl + P和Ctrl + N。 换句话说,您可以分别使用这些键代替向右,向左,向上和向下箭头。 缺少Home和End键? 您可以使用Ctrl + A和Ctrl + E。 想要一次移动页面吗? Ctrl + V向下移动页面,而Ctrl + Y向上移动页面。

But wait, there’s more! To move forward and backward one word at a time, you can use Ctrl+Space and Meta+Space (remember, that’s Alt+Space). And, if you’re really in a rush, you can hit Ctrl+_ and then type in the line number, a comma, and the column number to jump straight there.

但是,等等,还有更多! 要一次向前和向后移动一个单词,可以使用Ctrl + Space和Meta + Space(请记住,这是Alt + Space)。 而且,如果您真的很着急,可以按Ctrl + _,然后键入行号,逗号和列号,直接跳到那里。

07 go to line,column

If you want to see where your cursor currently is, sort of like nano-GPS, hit Ctrl+C.

如果要查看光标当前所在的位置(类似于nano-GPS),请按Ctrl + C。

08 show cursor location

复制,剪切和粘贴 (Copying, Cutting, and Pasting)

When we want to copy text in graphical environment, we highlight it with the cursor. Similarly, in nano we “mark” it by using the Ctrl+^ command. You simply move the cursor to where you want to start marking, and then you hit Ctrl+^ to “set” it. This will mark everything between the starting point up to and NOT including the cursor.

当我们想在图形环境中复制文本时,我们用光标突出显示它。 同样,在nano中,我们使用Ctrl + ^命令对其进行“标记”。 您只需将光标移动到要开始标记的位置,然后按Ctrl + ^即可对其进行“设置”。 这将标记从起点到终点(不包括光标)之间的所有内容。

09 marked text

Note that the cursor is on the empty space, and copying/cutting will not include this space. You can also mark backwards from your “set” point. Be careful, however, as you can edit text while your marking. If you messed up, just hit Ctrl+^ again to unset the marker and you can start over.

请注意,光标在空白处,并且复制/剪切将不包括该空间。 您也可以从“设置”点向后标记。 但是要小心,因为您可以在标记时编辑文本。 如果您搞砸了,只需再次按Ctrl + ^即可取消设置标记,然后您可以重新开始。

To copy the marked text, hit Meta+^. If, instead, you want to cut the text, hit Ctrl+K.

要复制标记的文本,请点击Meta + ^。 相反,如果要剪切文本,请按Ctrl + K。

To Paste your text, move the cursor to a suitable position and hit Ctrl+U.

要粘贴文本,请将光标移动到合适的位置,然后按Ctrl + U。

10 copied and pasted

If you want to remove an entire line of text, simply hit Ctrl+K without highlighting anything. This sometimes comes in handy when editing configuration files.

如果要删除整行文本,只需按Ctrl + K而不突出显示任何内容。 在编辑配置文件时,这有时会派上用场。

一些额外的捷径 (Some Extra Shortcuts)

You know how in notepad, you can force long lines of text to wrap-around into what look like paragraphs? You can toggle that feature in nano with the Meta+L shortcut. Since line wrapping is set to “on” by default, this usually comes in handy in the opposite way; for example, you’re writing a config file and want to disable line-wrapping.

您知道如何在记事本中强制将较长的文本行换成类似段落的内容吗? 您可以使用Meta + L快捷键在nano中切换该功能。 由于默认情况下,换行设置为“开”,因此通常以相反的方式派上用场; 例如,您正在编写配置文件,并且想要禁用换行。

11 line wrapping enabled

You can see that the line the cursor is on has a “$” at both the beginning and end. This signifies that there’s more text both before and after the portion being displayed on screen.

您会看到光标所在的行的开头和结尾都带有“ $”。 这表示在屏幕上显示该部分之前和之后都有更多的文本。

If you want to search for a text string, hit Ctrl+W, and enter your search term. This search can then be cancelled mid-execution by hitting Ctrl+C without destroying your buffer.

如果要搜索文本字符串,请按Ctrl + W,然后输入搜索词。 然后,可以在不破坏缓冲区的情况下通过按Ctrl + C取消执行中的搜索。

12 search

The previous search term appears in the square brackets, and leaving the line blank and hitting Enter will repeat that last search.

前一个搜索词出现在方括号中,并且将该行留空并按Enter键将重复上一次搜索。

And after you get really comfortable, you can turn that helpful section at the bottom off by hitting Meta+X to get more screen space for editing!

在您感到非常自在之后,您可以通过点击Meta + X来关闭底部的有用部分,以获取更多的编辑屏幕空间!

13 hidden help

一些历史 (Some History)

Nano was designed to be similar in look and feel to another program called Pico. Pico was the default text editor of Pine, an email program from back in the day that wasn’t distributed with a GPL-friendly license. This meant that redistribution was somewhat of a fuzzy area, and so the TIP project was born. “TIP Isn’t Pico” added some functionality that Pico lacked and was licensed for free distribution, and over time, became the nano we love to use today. For more information, check out the Nano Project’s History section on their FAQ.

Nano被设计为在外观上与另一个名为Pico的程序相似。 Pico是Pine的默认文本编辑器,Pine是从那时开始的电子邮件程序,但尚未通过GPL友好许可证进行分发。 这意味着重新分配在某种程度上是一个模糊的领域,因此TIP项目诞生了。 “提示不是Pico”增加了Pico缺少的一些功能,并获得了免费分发的许可,随着时间的流逝,它成为了我们今天喜欢使用的nano。 有关更多信息,请查看FAQ上的Nano Project的“历史记录”部分



The strength of nano lies in its simplicity of use. The shortcuts work just like in GUI-based word processors like Word and Open Office, so it’s just a matter of learning which ones do what. Everything outside of that is just simple text-editing. Next time you have to edit stuff on the command-line, we hope that you’ll be more comfortable with it now that you’ve gotten familiar with nano.

纳米的优势在于使用简单。 快捷方式的工作方式就像在基于GUI的字处理程序(如Word和Open Office)中一样,因此只需了解哪些功能可以完成工作即可。 除此之外,一切都只是简单的文本编辑。 下次您必须在命令行上编辑内容时,我们希望现在您已经对nano熟悉了,可以对此感到更舒服。

翻译自: https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/

linux nano命令

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值