Linux学习-day8

vim的使用

安装vim

  1. yum install vim -y
  2. 验证是否有vim

vim的使用

基本上 vi/vim 共分为三种模式,分别是:

  • 命令模式(Command mode)
    • 最长用的,按下字母,a,i,o(a 在光标前开始编辑,i是在光标处,开始编辑,o是在光标下一行开始编辑)
    • 当你使用vim 标记某个文件时,第一步就进入了命令模式。
    • 你此时可以按下键盘的几个快捷键,进入不同的指令模式。
    • 可以移动光标位置,输入快捷键指令,对文件进行编辑,如插入字符,复制,粘贴,删除等操作
  • 输入模式(Insert mode)
    • 可以对文件内容进行编辑。
    • 退出编辑模式(按下esc键,回到了命令模式)
  • 末行模式(Last line mode)底线模式
    • 从命令模式下 ,输入冒号,即进入了底线命令模式。
    • 进行一些特殊操作,如文本信息的查找,替换,保存,退出等;

还有一种特殊的可视化模式(多行操作模式),用于批量的列选操作。

底线模式

1.进入底线模式

按下ESC,输入: 进入底线模式

2.写入数据write

:w 保存写入

:w hello.txt 另存为文件

3.退出quit

:q! 退出文件,不保存;!代表强制退出

4.保存且退出

:wq!

5.搜索查找

/hello 输入ESC之后进入命令模式,/后面接的内容就是需要查找的内容,查到的会高亮显示

:noh 是取消高亮

6.替换

😒/源内容/新内容/ 替换第一个

😒/源内容/新内容/g 替换单行

:%s/源内容/新内容/ 替换全篇每行第一个

:%s/源内容/新内容/g 全篇替换

7.显示行号

:set nu 显示行号

:set nonu 取消显示

8.paste模式

vim的粘贴模式,会保留原格式:

:set paste 粘贴模式

:sey nopaste 取消粘贴模式

编辑模式

1.按字母a、i、o进入编辑模式

2.按ESC退出编辑模式,回到命令模式

可视化模式

先进入命令模式,按下ESC,再按下ctrl+v进入可视化模式,方向键选择可视化块,ESC退出可视化。

选中复制

1、光标放在在你想复制的地方,进入可视化模式;

2、选中你想要的内容区域;

3、按下y复制,p粘贴;

选中删除

1、光标放在在你想删除的地方,进入可视化模式;

2、选中你想要的内容区域;

3、按下d删除;

批量添加注释

注释指的是,备注、解释,一般用于大多数编程语言的脚本中,不会被加载的行,例如:

# def get_page_source(url):
#     resp = requests.get(url)
#     resp.encoding = 'gbk'
#     return resp.text

1、进入可视化模块;

2、选中要添加注释的行;

3、按下大写字母I,进入插入模式;

4、输入#;

5、按下ESC,退出后就出现了多行注释;

注:同样选择注释符,也可已进行删除;

彩色模式

shell

:syntax off 语法颜色关闭

:syntax on 语法颜色开启

vim故障处理

E325: ATTENTION
Found a swap file by the name ".test.swp"
owned by: root dated: Tue Mar 8 15:22:47 2022
file name: ~root/test
modified: YES
user name: root host name: server
process ID: 6258 (still running)
While opening file "test"
dated: Tue Mar 8 15:05:28 2022
(1) Another program may be editing the same file. If this is the case,
be careful not to end up with two different instances of the same
file when making changes. Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r test"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".test.swp"
to avoid this message.
Swap file ".test.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

故障原因

  1. 多人同时编辑了一个文件
  2. vim 编辑文件被异常关闭(如ssh断连、系统故障)

解决方法

  1. 恢复文件
1. 继续打开文件
vim test.txt
2. 发现swp错误提示
输入R ,recover恢复
3.继续编辑,然后正常保存退出
:wq!
4.删除swp文件即可 # 删除同级目录下同名(后缀名多个.swp)的隐藏文件
  1. 不恢复,直接删除
1.直接删除.swp文件,使用rm命令删除.swp即可。
2.使用vim提供的指令,忽略,删除swp文件。

昨日回顾&知识补充

关于rm命令注意事项

# 删除乐队组合下所有的文件内容
[root@linux0224 ~]#rm -rf /网易云音乐/华语/乐队组合/*

# 删除了乐队组合这个文件夹
[root@linux0224 ~]#rm -rf /网易云音乐/华语/乐队组合/  

关于tar

tar -xf   # 这是一个通用的,万能解压缩命令,已经可以自动适配,大多数压缩格式,自动的解压了gzip压缩的文件。

tar是打包命令
关于压缩,其实是gzip这样的命令
以及还有其他各种压缩指令,他们都是底层的压缩算法的不同,效率的不同,兼容性的不容
最主流的,你用gzip即可

tar  -z 调用gzip压缩指令了。

关于解压到指定目录
[root@localhost test_tar]# tar -xf all_tests.tar -C /tmp/all_test1/
[root@localhost test_tar]# 
[root@localhost test_tar]# 
[root@localhost test_tar]# ll -h /tmp/all_test1/
total 46M
-rw-r--r--. 1 root root 6.6M Mar  8 09:29 test1
-rw-r--r--. 1 root root 6.6M Mar  8 09:29 test2
-rw-r--r--. 1 root root 6.6M Mar  8 09:29 test3
-rw-r--r--. 1 root root 6.6M Mar  8 09:29 test4
-rw-r--r--. 1 root root 6.6M Mar  8 09:29 test5
-rw-r--r--. 1 root root 6.6M Mar  8 09:29 test6
-rw-r--r--. 1 root root 6.6M Mar  8 09:29 test7
[root@localhost test_tar]# 

下载网络文件

如何确保该文件的正确性(查看md5值)

[root@localhost ~]# md5sum nihao.txt
d41d8cd98f00b204e9800998ecf8427e  nihao.txt     可以根据这个校验值是否变化,来判断重要文件是否被篡改;

文件下载网址:https://tengine.taobao.org/ 软件官网

文件下载方式一

Windows环境下,下载后使用文件传输工具,发给Linux;

传输工具1:lrzsz

[root@localhost test_tar]# yum install lrzsz -y 

安装该工具后,会自动生成
rz  (接收)
sz   (send 发送)
两个命令 

3.获取win下载的那个文件

linux 接收,来自于win的文件

输入rz命令,接收

4.接收完毕后,验证该文件的正确性
[root@localhost test_tar]# md5sum tengine-2.3.3.tar.gz 
01651b1342c406b933490dd8f2962b36  tengine-2.3.3.tar.gz
[root@localhost test_tar]# 

扩充
,也可以直接win,拖拽到xshell里,即可传输

传输工具2:xftp

和xshell是一个系列的软件

xshell是专门用于ssh登录服务器的终端软件

xftp 专门用于win和linux之间传输大量文件的,且支持短点续传。

文件下载方式二

1.获取该软件的,下载链接即可
https://tengine.taobao.org/download/tengine-2.3.3.tar.gz

2.到linux中,使用命令下载wget即可获取一个链接的资源。
还得安装该命令
yum install wget -y

直接使用wget + 资源url(资源链接地址)即可。

wget https://tengine.taobao.org/download/tengine-2.3.3.tar.gz

下载网络中开源文件

1.wget下载即可
wget https://codeload.github.com/jumpserver/jumpserver/zip/refs/heads/dev

2.解压缩,如果该文件,并非是tar.gz进行压缩的,你就无法用tar命令去解压缩!!
目前已知它是zip压缩包

3.用unzip解压缩
[root@localhost opt]# unzip dev
posted on 2024-03-13 22:31  day_day_u_p  阅读(4)  评论(0编辑  收藏  举报