nano编辑器的使用

部署运行你感兴趣的模型镜像

被nano编辑器折腾了半天,收藏一下吧。省得以后到处找

我们以后基本都需要编辑文件来实现不同的设置,那么我们用什么来设置配置文件呢,用编辑器,就好比windows下的记事本和写字板,我们今天就来讲一下debian的默认编辑器----nano

首先我们在网络上看看有没nano的资料
网络上很少有nano的资料,那么我就来 给大家讲解一下nano的使用吧
就以编辑网络配置文件为例子吧

GNU nano 1.2.4,nano的版本 File: /etc/network/interfaces打开的文件的绝对地址

下面就是打开的文件的内容
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.254.20
netmask 255.255.255.0
network 192.168.254.0
broadcast 192.168.254.255
gateway 192.168.254.254
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 202.103.0.117 202.103.24.68
[ Read 17 lines ]
^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos
^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Txt ^T To Spell

这些是帮助栏目,呵呵^G表示ctrl+g一起按,呵呵

^G Get Help表示同时按ctrl和G,就是调出帮助菜单

我们来试一下
我按 了一下就调出了帮助菜单了,我下面就直接把快捷键表给大家,大家试试吧

一直以来vi都被人们说是最强大的编辑器,但gentoo和debian选择nano做了默认的编辑器
freebsd选择ee做了默认的编辑器,我相信在专业人士眼睛里面freebsd和redaht比较起来,
redhat基本没什么可以炫耀的,为什么他们不选择vi呢,因为vi操作比较复杂
而所谓的简单编辑器nano就简单,非常容易上手,说是简单编辑器
其实一点都不简单,只不过是nano谦虚一下罢了

这里声明一下^表示键盘上的ctrl键,上个只要是做过编程的朋友应该都清楚,^G表示同时按下ctrl和g
(F1)表示按(F1)也是一样的 ,M-表示使用alt+后面的键

^G ==F1) Invoke the help menu
调用帮助菜单

^X ==(F2) Close currently loaded file/Exit from nano
退出

^O ==(F3) Write the current file to disk == ^O WriteOut
保存
然后回车就保存了

^J ==(F4) Justify the current paragraph
调整当前段落(配置文件的不要用这东西,格式一下就出问题了哦)

^R ==(F5) Insert another file into the current one
插入其他的文件到当前的文件,而且查找文件的时候支持tab

^W ==(F6) Search for text within the editor

查找
^Y ==(F7) Move to the previous screen
上一屏幕
^V ==(F8) Move to the next screen
下一屏幕
^K ==(F9) Cut the current line and store it in the cutbuffer
裁减当前一排并保存在缓冲区

^U ==(F10) Uncut from the cutbuffer into the current line
将缓冲区的东西粘贴到此

^C ==(F11) Show the position of the cursor
显示光标位置

^T ==(F12) Invoke the spell checker, if available

调用拼写检查程序

^P Move up one line

向上移动一行
^N Move down one line

向下移动一

^F Move forward one character
向前移动光标一格

^B Move back one character
向后移动光标一格

^A Move to the beginning of the current line
移动到当前行的开头

^E Move to the end of the current line
移动到当前行的末尾

^L Refresh (redraw) the current screen
刷新当前屏幕

^^ (M-A) Mark text at the current cursor location
标记文本

^D Delete the character under the cursor

删除光标后一个字母
^H Delete the character to the left of the cursor
向左边删一个字母
^I Insert a tab character
插入一个tab值
^/ (F14) (M-R) Replace text within the editor

查找并且替换
^M Insert a carriage return at the cursor position
插入一个回车
^_ (F13) (M-G) Go to a specific line number

跳转到某行
^Space Move forward one word

前进一个单词
M-Space Move backward one word
后退一个单词
M-] Find other bracket
搜索下一个括号

M-< Open previously loaded file
打开先前加载的文件

M-> Open next loaded file

打开下一个加载的文件

M-C Constant cursor position enable/disable

M-I Auto indent enable/disable
是否首行缩进

M-Z Suspend enable/disable
是否悬挂

M-X Help mode enable/disable
帮助模式

M-M Mouse support enable/disable

鼠标支持

M-Y Color syntax highlighting enable/disable
语法加亮

这个就是退出了哦

好了nano 的编辑器就说这样多了
然后我们来说一下基本的几个配置文件以及地方
首先是打开命令行高效输入的位置
看到了高级的命令行补全,连软件包的名字都不需要记了哦,呵呵,是不是很爽哦

怎么ls没颜色了,你们是不是在redhat里面看到过颜色啊,那我们来改
看到了没,兰色是目录,白色是文件,绿色是可以运行的文件

cnrot:/# ll
-bash: ll: command not found
告诉我们ll没这个命令
那我们来做一个自己定义的命令吧
记住要注销才生效,不需要重新启动的哦
看到了没
看到了没,这是自己定义命令哦
好了,我现在 给大家说几个文件的位置吧

怕大家找不到
首先是网络配置文件/etc/network/interfaces

GNU nano 1.2.4 File: /etc/network/interfaces Modified

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.254.20
netmask 255.255.255.0
network 192.168.254.0
broadcast 192.168.254.255
gateway 192.168.254.254
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 202.103.0.117 202.103.24.68

安装源配置文件
GNU nano 1.2.4 File: /etc/apt/sources.list

#deb file:///cdrom/ sarge main

deb cdrom:[Debian GNU/Linux 3.1 r0a _Sarge_ - Official i386 Binary-1 (20050607)$

deb http://debian.cn99.com/debian/ stable main
deb-src http://debian.cn99.com/debian/ stable main

deb http://security.debian.org/ stable/updates main contrib

您可能感兴趣的与本文相关的镜像

PyTorch 2.6

PyTorch 2.6

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

### 编写包含 `if` 和 `case` 的 Shell 脚本 在 Linux 系统中,Nano 是一种简单易用的命令行文本编辑器。以下是如何使用 Nano 编辑器分别创建两个脚本文件 `if.sh` 和 `case.sh`,它们各自实现了 `if` 条件语句和 `case` 多分支选择逻辑。 #### 使用 Nano 编写 if.sh 脚本 此脚本检查 `/root/txtfile/ztg1.txt` 文件是否存在。如果存在,则显示其内容;否则列出该目录下的所有文件。 ```bash #!/bin/bash # Check whether the file ztg1.txt exists under /root/txtfile directory. FILE="/root/txtfile/ztg1.txt" if [ -f "$FILE" ]; then echo "The file $FILE exists and its content is as follows:" cat "$FILE" else echo "The file $FILE does not exist. Listing contents of /root/txtfile instead:" ls "/root/txtfile" fi ``` 要使用 Nano 创建并保存上述脚本,请按照以下步骤操作: 1. 打开终端并键入 `nano if.sh` 启动 Nano 编辑器[^1]。 2. 将上面的代码复制粘贴到 Nano 编辑窗口中。 3. 按 Ctrl+O 保存更改,按 Enter 确认文件名。 4. 按 Ctrl+X 退出 Nano。 赋予脚本可执行权限并通过 Bash 解释器运行它[^2]: ```bash chmod +x if.sh ./if.sh ``` #### 使用 Nano 编写 case.sh 脚本 此脚本进入 `/root/txtfile` 目录后提示用户输入数字 `[1-2]` 并根据用户的输入决定显示哪个文件的内容。如果输入不在范围内,则返回错误消息。 ```bash #!/bin/bash # Navigate to /root/txtfile and display files based on user input using a menu system with 'case'. cd /root/txtfile || { echo "Failed to change directory"; exit 1; } echo "Select an option by entering a number (1 or 2): " echo "1. Show first_file.txt" echo "2. Show second_file.txt" read choice case $choice in 1) if [ -f "first_file.txt" ]; then cat "first_file.txt" else echo "File first_file.txt does not exist." fi ;; 2) if [ -f "second_file.txt" ]; then cat "second_file.txt" else echo "File second_file.txt does not exist." fi ;; *) echo "Wrong selection!" ;; esac ``` 同样地,在 Nano 中创建 `case.sh` 脚本的方法如下: 1. 输入 `nano case.sh` 开启 Nano 编辑环境[^1]。 2. 插入以上代码片段至编辑区。 3. 完成编辑后依次按下 Ctrl+O、Enter 键存储改动再按 Ctrl+X 关闭 Nano。 设置脚本为可执行状态并调用之[^2]: ```bash chmod +x case.sh ./case.sh ``` --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值