一、定位
1 全文定位:
命令行模式:
文档第一行:gg
文档最后一行:G
2 打印行号:
: set number 或者 :set nu #显示行号
: set nonumber 或者 : set nonu#不显示行号
:100 或者 100G #定位到 第100行
3 本屏内定位:
第一行: H
中间行: M
最后一行 : L
输入内容:
命令模式下:
i 进入插入模式 ,在光标位置插入
o: 在光标下方新建空行 插入
O: 在光标上方新建空行 插入
4 复制文本内容 ,粘贴
nyy : n行数, 在光标所在位置向下 复制n 行 : 2yy ,包含光标所在行的向下2行
p: 从光标行,下一行开始粘贴 ,向下
P: 从光标行,上一行开始粘贴 ,向上
yy: 复制当前行
5 删除:
dd: 删除当前行
ndd: 将光标所在行向下删除n行,包含当前行 3dd:
6 查找:
命令行模式:
/Listen
7 查找 替换:
:%s/Listen 80/Listen 8080 #在全文中查找,替换第一个匹配的内容
:%s/Listen 80/Listen 8080/g #在全文中查找,替换所有
\: s/Listen 8080/Listen 8080 #当前行查找替找 替换第一个匹配的内容
二、输入,标准输出 ,错误输出: 文本 输出到 当前 terminal 存在内存
标准输出:正确
[root@server0 Desktop]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:00:00:0b brd ff:ff:ff:ff:ff:ff
inet 172.25.0.11/24 brd 172.25.0.255 scope global dynamic eth0
valid_lft 20206sec preferred_lft 20206sec
inet6 fe80::5054:ff:fe00:b/64 scope link
valid_lft forever preferred_lft forever
[root@server0 Desktop]#
$? # 查询上一条指令是否执行成功
[root@server0 Desktop]# echo $? # 等于 0 正确执行
0
[root@server0 Desktop]#
错误输出:
[root@server0 Desktop]# ipfef
bash: ipfef: command not found...
[root@server0 Desktop]# echo $? # 非0 表示 错误
127
[root@server0 Desktop]#
输入: 发送邮件
输入重定向:
[root@server0 Desktop]# mail -s test root@classroom.example.com < /etc/hosts
输出重定向:
> : 正确输出 覆盖
> [root@server0 tmp]# > httpd.conf
[root@server0 tmp]# cat httpd.conf
[root@server0 tmp]#
[root@server0 tmp]# echo "hello" > httpd.conf
[root@server0 tmp]# cat httpd.conf
hello
[root@server0 tmp]#
>>: 正确输出 追加到文件 最后
[root@server0 tmp]# echo "ok" >> httpd.conf
[root@server0 tmp]# cat httpd.conf
hello123
ok
[root@server0 tmp]#
错误输出 重定向:
2> : 错误输出 重定向: 覆盖
[root@server0 tmp]# fewfe 2> /tmp/httpd.conf
[root@server0 tmp]# cat /tmp/httpd.conf
bash: fewfe: command not found...
[root@server0 tmp]#
2>> : 错误输出 重定向:追加
[root@server0 tmp]# cat /etc/testfff 2>> /tmp/httpd.conf
[root@server0 tmp]# cat /tmp/httpd.conf
bash: fewfe: command not found...
cat: /etc/testfff: No such file or directory
[root@server0 tmp]#
&> : 正确与错误都 重定向
[root@server0 tmp]# useradd zhangsan &> /tmp/httpd.conf
[root@server0 tmp]# cat /etc/hosts &>> /tmp/httpd.conf
[root@server0 tmp]# useradd zhangsan &>> /tmp/httpd.conf
[root@server0 tmp]# cat /tmp/httpd.conf
useradd: user 'zhangsan' already exists
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.254 classroom.example.com
172.25.254.254 content.example.com
useradd: user 'zhangsan' already exists
[root@server0 tmp]#
特殊文件:
/dev/null : 空 ,黑洞
/dev/zero : 无限的零
产生块文件:dd
[root@server0 tmp]# dd if=/dev/zero of=/tmp/bigfile2 bs=1M count=2048
管道符 :命令1 | 命令2 将前一个命令1的文本输出 ,输入给 命令2 文本处理命令
文本处理的工具:
1) grep : 行文本处理 ,过滤行
词过滤:
[root@server0 tmp]# df -T | grep -w /
/dev/sda1 xfs 10473900 3241420 7232480 31% /
[root@server0 tmp]#
输出匹配行和下几行
[root@server0 tmp]# cat /etc/hosts |grep -A 2 ::1
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.254 classroom.example.com
[root@server0 tmp]#
匹配文本开头的行 grep ^字符串
[root@server0 tmp]# cat /etc/postfix/main.cf | grep ^#
取反:grep -v
[root@server0 tmp]# cat /etc/postfix/main.cf | grep -v ^#
匹配行尾:
[root@server0 tmp]# cat /etc/passwd |grep /bin/bash$
root:x:0:0:root:/root:/bin/bash
student:x:1000:1000:Student User:/home/student:/bin/bash
zhangsan:x:2001:2001::/home/zhangsan:/bin/bash
lisi:x:2002:2002::/home/lisi:/bin/bash
wangwu:x:2003:2003::/home/wangwu:/bin/bash
[root@server0 tmp]#
去掉空行:
[root@server0 tmp]# cat /etc/postfix/main.cf | grep -v ^# |grep -v ^$
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
2) 列过滤工具: awk
[root@server0 tmp]# df -T | grep -w /
/dev/sda1 xfs 10473900 3241572 7232328 31% /
[root@server0 tmp]#
[root@server0 tmp]# df -T | grep -w / | awk -F " " '{print $5}'
7232328
[root@server0 tmp]#