技术栈系列基础篇7-linux常见命令
bash -c、xargs
bash -c
通常使用shell去运行脚本,两种方法 :
bash xxx.sh
bash -c "cmd string"
如果用bash -c 那么bash 会从第一个非选项参数后面的字符串中读取命令,如果字符串有多个空格,第一个空格前面的字符串是要执行的命令,也就是$0, 后面的是参数,即$1,$2….
xargs
-0, --null Items are separated by a null, not whitespace.
Disables quote and backslash processing
-a, --arg-file=FILE Read arguments from FILE, not standard input
-d, --delimiter=CHARACTER Input items are separated by CHARACTER, not by
blank space. Disables quote and backslash
processing
-E END If END occurs as a line of input, the rest of
the input is ignored.
-e [END], --eof[=END] Equivalent to -E END if END is specified.
Otherwise, there is no end-of-file string
--help Print a summary of the options to xargs.
-I R same as --replace=R (R must be specified)
-i,--replace=[R] Replace R in initial arguments with names
read from standard input. If R is
unspecified, assume {}
-L,-l, --max-lines=MAX-LINES Use at most MAX-LINES nonblank input lines per
command line
-l Use at most one nonblank input line per
command line
-n, --max-args=MAX-ARGS Use at most MAX-ARGS arguments per command
line
-P, --max-procs=MAX-PROCS Run up to max-procs processes at a time
-p, --interactive Prompt before running commands
--process-slot-var=VAR Set environment variable VAR in child
processes
-r, --no-run-if-empty If there are no arguments, run no command.
If this option is not given, COMMAND will be
run at least once.
-s, --max-chars=MAX-CHARS Limit commands to MAX-CHARS at most
--show-limits Show limits on command-line length.
-t, --verbose Print commands before executing them
--version Print the version number
-x, --exit Exit if the size (see -s) is exceeded
xargs
默认的命令是 echo
,这意味着通过管道传递给 xargs 的输入将会包含换行和空白,不过通过 xargs 的处理,换行和空白将被空格取代。
默认情况下xargs将其标准输入中的内容以空白(包括空格、Tab、回车换行等)分割成多个之后
当作命令行参数传递给其后面的命令,并运行之,我们可以使用 -d 命令指定分隔符
参考示例
ls ./src/server/protobuf/*.pb.go | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'
步骤拆解
- ls ./src/server/protobuf/*.pb.go,将文件目录下的文件列出
- |,管道
- xargs -n1 -IX,命令在执行的时候一次用的argument的个数,默认是用所有的,-I是指将X字符作为参数的替换,格式为
-I R
,R可以为一个特殊的字符,起到替换参数的作用 - bash -c,使用bash解释命令
- 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}',将X参数文件内每行
,omitempty
字段替换成空(预览模式)并输出到文件X.tmp,并且将文件 X.tmp 命名为X
Linux三剑客(grep、sed、awk)
grep
用于查询指定内容,打印匹配文本行。
格式:grep [-args] 'keywords' file [file1] [file..n]
常用参数:
- -r 递归查询,一般用于文件为目录
- -i (-y) 忽略大小写
- -n 显示行号
- -l 只显示文件名
- -w 只显示全字符匹配的列
- -x 只显示全列匹配的列
- -o 只显示匹配部分
- -v 反向匹配
- -c 计算匹配数
- -e 用于匹配多个字符
从文本中查询打印内容
# 查看测试文本
[root@VM_0_3_centos ~]# cat text
1:123
2:234
3:345
4:456
5:567
6:678
7:789
# -r递归查询,-l只显示文件,查看包含123的文件
[root@VM_0_3_centos ~]# grep -rl '123' ./
./.bash_history
./awk.text
./d.text
./text
# -n显示行号,查看包含3的行
[root@VM_0_3_centos ~]# grep -n '3' ./text
1:1:123
2:2:234
3:3:345
# -v,查看不包含3的行
[root@VM_0_3_centos ~]# grep -v '3' ./text
4:456
5:567
6:678
7:789
# -c,计算包含3的行数
[root@VM_0_3_centos ~]# grep -c '3' text
3
# -e,匹配多个条件
[root@VM_0_3_centos ~]# grep -e '3' -e '4' text
1:123
2:234
3:345
4:456
# -o, 只输出匹配的文本
[root@VM_0_3_centos ~]# grep -o '23' text
23
23
# -x,只匹配全行的数据
[root@VM_0_3_centos ~]# grep -x '123' text
[root@VM_0_3_centos ~]# grep -x '1:123' text
1:123
从管道输入中查询打印内容
[root@VM_0_3_centos proc]# cat cpuinfo | grep -n 'core'
12:core id : 0
13:cpu cores : 1
sed
sed在处理文本时是逐行读取内容,读到匹配的行就根据指令做操作,不匹配就跳过,常用于对文件的
增加``删除``修改``查询
sed的常用选项:
- a:追加 向匹配行后面插入内容
- i:插入 向匹配行前插入内容
- c:覆盖 覆盖匹配行的内容
- s:替换 替换掉匹配的内容
- d:删除 删除匹配的内容
- p:打印 打印出匹配的内容,通常与-n选项和用
- =:用来打印被匹配的行的行号
- n:读取下一行,遇到n时会自动跳入下一行
- r,w:读和写编辑命令,r用于将内容读入文件,w用于将匹配内容写入到文件
s命令修改文本
# 查看测试文本
[root@VM_0_3_centos ~]# cat text
1:123
2:234
3:345
4:456
5:567
6:678
7:789
# 预览模式-修改第一个匹配文本(此时源文件内容不会修改)
[root@VM_0_3_centos ~]# sed 's/3/0/' text
1:120
2:204
0:345
4:456
5:567
6:678
7:789
# 预览模式-修改所有匹配文本(此时源文件内容不会修改)
[root@VM_0_3_centos ~]# sed 's/3/0/g' text
1:120
2:204
0:045
4:456
5:567
6:678
7:789
# -i编辑模式修改文本(此时源文件会修改)
[root@VM_0_3_centos ~]# sed -i 's/123/s123/' text
[root@VM_0_3_centos ~]# cat text
1:s123
2:234
3:345
4:456
5:567
6:678
7:789
# -n 修改默认输出,输出只修改的行
[root@VM_0_3_centos ~]# sed -n 's/123/s123/p' text
1:s123
c命令覆盖文本所在行
[root@VM_0_3_centos ~]# sed '/3/c0' text
0
0
0
4:456
5:567
6:678
7:789
d命令删除文本
# 测试文本
[root@VM_0_3_centos ~]# cat d.text
1:123
2:234
3:345
4:456
5:567
6:678
7:789
# 预览模式-删除第一行
[root@VM_0_3_centos ~]# sed '1d' d.text
2:234
3:345
4:456
5:567
6:678
7:789
# 预览模式-删除最后一行
[root@VM_0_3_centos ~]# sed '$d' d.text
1:123
2:234
3:345
4:456
5:567
6:678
# 预览模式-删除匹配行
[root@VM_0_3_centos ~]# sed '/3/d' d.text
4:456
5:567
6:678
7:789
# -i编辑模式-删除空行
[root@VM_0_3_centos ~]# sed -i '/^$/d' d.text
1:123
2:234
3:345
4:456
5:567
6:678
7:789
# -预览模式-删除匹配除外所有行
[root@VM_0_3_centos ~]# sed '/3/!d' d.text
1:123
2:234
3:345
# -预览模式-删除1到2行
[root@VM_0_3_centos ~]# sed '1,2d' d.text
3:345
4:456
5:567
6:678
7:789
# -预览模式-从第一行开始,每2行就删除
[root@VM_0_3_centos ~]# sed '1~2d' d.text
2:234
3:345
5:567
7:789
i/a命令新增文本
# 预览模式-向第二行后面插入文本
[root@VM_0_3_centos ~]# sed '2a234aaaaa' text
1:123
2:234
234aaaaa
3:345
4:456
5:567
6:678
7:789
# 预览模式-向第最后一行后面插入文本
[root@VM_0_3_centos ~]# sed '$aenda' text
1:123
2:234
3:345
4:456
5:567
6:678
7:789
enda
# 预览模式-向所有匹配行后面新增文本
[root@VM_0_3_centos ~]# sed '/3/aa' text
1:123
a
2:234
a
3:345
a
4:456
5:567
6:678
7:789
# 预览模式-向最后一行前面插入文本
[root@VM_0_3_centos ~]# sed '$iendi' text
1:123
2:234
3:345
4:456
5:567
6:678
endi
7:789
-n选项 p命令打印输出文本
# 打印第二行
[root@VM_0_3_centos ~]# sed -n '2p' text
2:234
# 打印1到4行
[root@VM_0_3_centos ~]# sed -n '1,4p' text
1:123
2:234
3:345
4:456
# 从1行开始,每2行打印一次
[root@VM_0_3_centos ~]# sed -n '1~2p' text
1:123
3:345
5:567
7:789
# 打印匹配行
[root@VM_0_3_centos ~]# sed -n '/6/p' text
4:456
5:567
6:678
# 打印从匹配行开始,后4行
[root@VM_0_3_centos ~]# sed -n '/1/,4p' text
1:123
2:234
3:345
4:456
=打印行号
# 打印最后一行行号
[root@VM_0_3_centos ~]# sed -n '$=' text
7
# 打印匹配行号
[root@VM_0_3_centos ~]# sed -n '/3/=' text
1
2
3
awk
awk是一种编程语言,用于在linux/unix下对文本数据进行处理,数据可以来自标准输入,文件或其他命令的输出。格式:awk 'BEGIN{ commands } pattern{ commands } END{ commands }' filenames
BEGIN语句块在awk开始从输入流中读取行之前被执行,这是一个可选的语句块,比如变量初始化、打印输出表格的表头等语句通常可以写在BEGIN语句块中。
END语句块在awk从输入流中读取完所有的行之后即被执行,比如打印所有行的分析结果这类信息汇总都是在END语句块中完成,它也是一个可选语句块。
pattern语句块中的通用命令是最重要的部分,它也是可选的。如果没有提供pattern语句块,则默认执行{ print },即打印每一个读取到的行,awk读取的每一行都会执行该语句块。
常用命令选项
- -F fs fs指定输入分隔符,fs可以是字符串或正则表达式,如-F:
- -v var=value 赋值一个用户定义变量,将外部变量传递给awk
- -f scripfile 从脚本文件中读取awk命令
- -mfr val 对val值设置内在限制,-mf选项限制分配给val的最大块数目;-mr选项限制记录的最大数目。这两个功能是Bell实验室版awk的扩展功能,在标准awk中不适用。
awk常用内置变量
$n 当前记录的第n个字段,比如n为1表示第一个字段,n为2表示第二个字段。
$0 这个变量包含执行过程中当前行的文本内容。
FILENAME 当前输入文件的名。
FNR 同NR,但相对于当前文件。
FS 字段分隔符(默认是任何空格)。
IGNORECASE 如果为真,则进行忽略大小写的匹配。
NF 表示字段数,在执行过程中对应于当前的字段数。
NR 表示记录数,在执行过程中对应于当前的行号。
RS 记录分隔符(默认是一个换行符)。
awk的分隔符还分为两种,“输入分隔符” 和 “输出分隔符”
输入分隔符,英文原文为field separator,此处简称为FS,awk默认以空白字符为分隔符对每一行进行分割。
输出分割符,英文原文为output field separator,此处简称为OFS,即当我们要对处理完的文本进行输出的时候,以什么文本或符号作为分隔符。
AWK 包含两种特殊的模式:BEGIN 和 END。
BEGIN 模式指定了处理文本之前需要执行的操作
END 模式指定了处理完所有行之后所需要执行的操作
➜ /data cat 1.log
a b c d
1 2 3 4
➜ /data awk 'BEGIN{print "b1","b2"} {print $1,$4} END{print "e1","e2"}' 1.log
b1 b2
a d
1 4
e1 e2
➜ /data
# 输出每一行内容
[root@VM_0_3_centos ~]# awk '{print $0}' awk.text
1:123
2:234
3:345
# 输出以:分隔的第一列
[root@VM_0_3_centos ~]# awk -F: '{print $1}' awk.text
1
2
3
# 输出以:分隔的第二列
[root@VM_0_3_centos ~]# awk -F: '{print $2}' awk.text
123
234
345
# 格式化输出(在awk的print语句块中双引号是被当作拼接符使用)
[root@VM_0_3_centos ~]# awk -F: '{print $1 "@" $2}' awk.text
1@123
2@234
3@345
# 输出第一列和第二列内容
[root@VM_0_3_centos ~]# awk '-F:' '{print $1,$2}' awk.text
1 123
2 234
3 345
# 输出每一行行号,并且输出总行数
[root@VM_0_3_centos ~]# awk '{print NR,$1,$2} END{print "total rows:" NR}' awk.text
1 1:123
2 2:234
3 3:345
total rows:3
# 可以用-v传递外部变量
[root@VM_0_3_centos ~]# VAR=666
[root@VM_0_3_centos ~]# echo | awk -v a=$VAR '{print a}'
666
# next用于跳过当前行
[root@VM_0_3_centos ~]# awk 'NR%2==0{next}{print NR,$0}' awk.text
1 1:123
3 3:345
常用命令,设置
一台新linux服务器,会做什么操作
- groupadd test 添加组
- useradd -g test andre 新建用户andre 到 test组
- passwd,更改服务器密码
- 防火墙设置
- systemctl status firewalld查看防火墙状态
- systemctl start firewalld 开启防火墙
- systemctl stop firewalld 关闭防火墙
- firewall-cmd --zone=public --add-port=80/tcp --permanent // 开启访问端口
- --zone 作用域
- --add-port=80/tcp 开启端口
- --permanent 永久生效
- firewall-cmd --list-port 查询所有端口
- firewall-cmd --realod 重启防火墙 - ssh-keygen生成公钥私钥
- yum install vim 安装vim
- vim /etc/sysconfig/network-scripts/ifcfg-eth0 设置网络信息,静态IP等
常用命令
- 用户/文件 权限
- cat /etc/passwd 显示用户列表
- cat /etc/group 显示用户组列表
- useradd -g test andre 创建用户
- groupadd test 创建用户组
- passwd 修改密码
- su 切换用户
- chown runoob:runoobgroup file1.txt // 设置文件的关联用户和组
- chmod +x 1.log 添加之行权限 rwx(用户权限) rwx(用户组权限) rwx(其他用户权限) - 文件管理
- ls -l // 列出文件详细信息
- cd // 切换目录
- cat // 查看文本信息,同样的查看文本信息还有, more
- mkdir // 创建陌路
- rm -f xx.log // 删除文件信息
- cp // 复制文件内容
- mv src dest // 移动文件
- ln -s 源文件或目录 // 创建软连接
- scp // 远程复制 - 搜索/文本处理
- grep // 从文本中查询字符串
- find . -name ".c" // 查找文件,查找当前目录下 名字为 .c的文件
- wc // 统计文本行数
- pwd // 显示当前目录
- tree // 显示树形目录
- more less // 显示文本内容
- tail // 显示文件尾部内容
- ls ./src/server/protobuf/*.pb.go | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'
- | 管道传输
- ls // 列出文件
- xargs -n1 -IX
- -n num 后面加次数,表示命令在执行的时候一次用的argument的个数,默认是用所有的。
- bash -c “cmd string” // 通常使用shell去运行脚本,两种方法 bash xxx.sh,另外一种就是bash -c “cmd string”
- sed 文件处理,例如 sed s/a/b/g 1.log 就是将1.log的文本中 a 字符 替换成b字符
- awk -F: '{print $1; print $2}' /etc/passwd // 文本行处理器,打印出文件每一行的第一 和第二个字段. -F 为定义分隔符 - 资源查询
- df -hl // 查看磁盘大小
- du -sh // 查看目录大小
- ps -axu // 查询瞬间进程状态
- free // 查询内存状态
- top // 查询实时变化进程
- ulimit
- -s 查询linux栈大小
- -n 查看fd默认值 - 网络查询
- ifconfig // 查看网络情况,网络地址,网络掩码,网桥,网口
- netstat -napt // 查看网络连接情况
- lsof -i:端口 // 查询端口进程信息 - 打包压缩
- tar -czvf xxx.tar xxxx // 打包压缩
- tar -xzvf xxx.tar 解压缩 - 其他
- yum 命令 安装包
- yum search mysql // 搜索 mysql包
- yum list // 列出所有可用包
- yum install mysql // 安装mysql包,如果不指定版本号,安装最稳定版本
- yum update mysql // 更新mysql包
- yum update // 更新所有包
- yum remove mysql // 删除mysql包
- yum check-update // 检查可更新的包
- ssh -h192.168.1.178 -u andre -p // ssh 远程登录 端口是22
- reboot shutdown 重启,关机
分析CPU 内存 IO 网络
- df -hl 磁盘分析
- 文件系统,描述文件
- 容量 总容量
- 已用容量
- 可用容量
- 已用百分比
- 挂载位置 - free 内存使用
- Mem 行(第二行)是内存的使用情况。
- Swap 行(第三行)是交换空间的使用情况。
- total 列显示系统总的可用物理内存和交换空间大小。
- used 列显示已经被使用的物理内存和交换空间。
- free 列显示还有多少物理内存和交换空间可用使用。
- shared 列显示被共享使用的物理内存大小。
- buff/cache 列显示被 buffer 和 cache 使用的物理内存大小。
- available 列显示还可以被应用程序使用的物理内存大小。 - top 命令
- PID 进程id
- USER 用户名
- PR 优先级
- NI nice值 -20到19,越小优先级越高
- VIRT 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
- SWAP 进程使用的虚拟内存中,被换出的大小,单位kb // 将不常用的内存交换到磁盘,提高物理内存使用性能和空间
- RES 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
- CODE 可执行代码占用的物理内存大小,单位kb
- DATA 可执行代码以外的部分(数据段+栈)占用的物理内存大小,单位kb
- SHR 共享内存大小,单位k
- 虽然进程只使用了几个共享库的函数,但它包含了整个共享库的大小
- 计算某个进程所占的物理内存大小公式:RES – SHR
- %CPU 上次更新到现在的CPU时间占用百分比
- %MEM 进程使用的物理内存百分比
- TIME 进程使用的CPU时间总计,单位秒;TIME+ 进程使用的CPU时间总计,单位1/100秒
- COMMAND 命令名/命令行
- IO使用情况
- iotop -oP,只展示有IO行为的进程
- pidstat 命令,参数如下:
- -u, 展示CPU使用统计
- PID 进程Id
- %user,进程在用户态所占CPU时间比率
- %system,进程在内核态所占CPU时间比率
- %guest,任务花费在虚拟机上所占的CPU使用率(运行在虚拟处理器)
- %CPU,进程所占的CPU时间比例
- CPU, 进程在哪个核运行
- Command 拉起进程的命令
- -r 展示内存统计
- minflt/s:每秒次缺页错误次数(minor page faults),从内存中加载数据时每秒出现的小的错误的数目
- majflt/s: 每秒主缺页错误次数(major page faults),从内存中加载数据时每秒出现的较大错误的数目,这些要求从磁盘载入内存页面。
- VSZ: 虚拟容量:整个进程的虚拟内存使用(kb)
- RSS: 长期内存使用:任务的不可交换物理内存的使用量(kb)
- %MEM: 该进程使用内存的百分比
- Command: 拉起进程对应的命令
- -d ,展示IO统计
- kB_rd/s: 每秒进程从磁盘读取的数据量(以kB为单位)
- kB_wr/s: 每秒进程向磁盘写的数据量(以kB为单位)
- Command: 拉起进程对应的命令
- iftop 查看网咯IO情况
- TX:发送流量
- RX:接收流量
- TOTAL:总流量
- Cumm:运行iftop到目前时间的总流量
- peak:流量峰值
- rates:分别表示过去 2s 10s 40s 的平均流量
防火墙设置
- 防火墙命令用firewalld取代了iptables了。
- 查看防火墙状态 systemctl status firewalld
- 临时关闭防火墙命令,reboot之后,防火墙自动起来。 systemctl stop firewalld
- 永久关闭防火墙命令。reboot之后,防火墙不会自动启动 systemctl disable firewalld
- 启动防火墙命令 systemctl enable firewalld - 用systemctl 代替了service,不过为了向后兼容,centos7中,service还是可以用的。
- 如使用systemctl关闭防火墙
- systemctl stop firewalld.service - firewalld的基本使用
- 启动: systemctl start firewalld
- 查看状态: systemctl status firewalld
- 停止: systemctl disable firewalld
- 禁用: systemctl stop firewalld - systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
- 启动一个服务:systemctl start firewalld.service
- 关闭一个服务:systemctl stop firewalld.service
- 重启一个服务:systemctl restart firewalld.service
- 显示一个服务的状态:systemctl status firewalld.service
- 在开机时启用一个服务:systemctl enable firewalld.service
- 在开机时禁用一个服务:systemctl disable firewalld.service
- 查看服务是否开机启动:systemctl is-enabled firewalld.service
- 查看已启动的服务列表:systemctl list-unit-files|grep enabled
- 查看启动失败的服务列表:systemctl --failed - 配置firewalld-cmd
- 查看版本: firewall-cmd --version
- 查看帮助: firewall-cmd --help
- 显示状态: firewall-cmd --state
- 查看所有打开的端口: firewall-cmd --zone=public --list-ports
- 更新防火墙规则: firewall-cmd --reload
- 查看区域信息: firewall-cmd --get-active-zones
- 查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
- 拒绝所有包:firewall-cmd --panic-on
- 取消拒绝状态: firewall-cmd --panic-off
- 查看是否拒绝: firewall-cmd --query-panic - 那怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone=public --remove-port=80/tcp --permanent
生成随机密码的方式
随机纯数字(20位为例):
head /dev/urandom | tr -dc 0-9 | head -c 20
随机小写字母+数字(20位为例):
head /dev/urandom | tr -dc a-z0-9 | head -c 20
随机大小写字母+数字(20位为例):
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20
mysql免登陆
生成密码方法
其中一种:
cat /dev/urandom | LC_ALL=C tr -dc ":graph:" | fold -w 10 |head -10
免密码登录设置
login-path是MySQL5.6开始支持的新特性。通过借助mysql_config_editor工具将登陆MySQL服务的认证信息加密保存在.mylogin.cnf文件(默认位于用户主目录) 。之后,MySQL客户端工具可通过读取该加密文件连接MySQL,避免重复输入登录信息,避免敏感信息暴露。
mysql_config_editor使用帮助:
配置:
mysql_config_editor set --login-path=test --user=test_user --host=127.0.0.1 --port=3306 --password
其中可配置项
-h,–host=name 添加host到登陆文件中
-G,–login-path=name 在登录文件中为login path添加名字(默认为client)
-p,–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
-u,–user 添加用户名到登陆文件中
-S,–socket=name 添加sock文件路径到登陆文件中
-P,–port=name 添加登陆端口到登陆文件中
显示配置:
mysql_config_editor print --login-path=test #显示执行的login-path配置
mysql_config_editor print --all #显示所有的login-path信息
删除配置:
mysql_config_editor remove --login-path=test
其中可删除项
-h,–host=name 添加host到登陆文件中
-G,–login-path=name 在登录文件中为login path添加名字(默认为client)
-p,–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
-u,–user 添加用户名到登陆文件中
-S,–socket=name 添加sock文件路径到登陆文件中
-P,–port=name 添加登陆端口到登陆文件中
重置配置:
mysql_config_editor reset --login-path=test
使用login-path登录:
shell>mysql --login-path=test
若要登录其他主机、其他端口,或者添加其他额外参数,直接在上述命令后添加即可
shell>mysql --login-path=test -h host1 -P port1 #登录host1:poet1上的MySQL
shell>mysql --login-path=test -h host1 -P port1 test_db #登录 host1:poet1 上的MySQL中的test_db库
自动登录shell脚本
#!/usr/bin/expect
spawn ssh -p {端口号} {user}@{IP}
expect "password:"
send "{password}\\r"
interact
有趣的生成图形命令
sl 命令,会看到一辆火车从右到左开
➜ ~ sl
cowsay 命令,用字符打印牛、羊等命令
➜ ~ cowsay
cmatrix 命令 黑客帝国的矩阵动画效果
➜ ~ cmatrix
figlet 命令,由ASCII字符组成,把文本显示成标题栏
➜ ~ figlet andrekzwu