shall脚本常用的命令

1.diff命令

diff是用来比较两个文加或目录的不同
diff westos westos1
读取过程中a表示添加,c表示更改,d表示删除,<表示第一个文件中的内容,>表示第二个文件中的内容,—分割线。
在这里插入图片描述

diff -b westos westos1 不检查空个字符的不同
diff -B westos westos1 不检查空白行的不同
diff -i westos westos1 不检查大小写的不同
diff -p westos westos1 文件为c语音时,显示差异所在函数名称。
diff -u westos westos1 > westos.path 生成补丁
在这里插入图片描述
diff -r test test1/ 比较子目录中的文件不同
在这里插入图片描述

2.patch命令

yum install patch -y 下载patch
在这里插入图片描述

patch westos westos.path 使用补丁使westos变为westos1
patch -b westos westos.path 生成文件时备份原文件westos.orig
在这里插入图片描述

3.cut命令

cut命令多用与字符截取
cut -d 指定分隔符
cut -f 1,4|1-4 指定截取的列
cut -c 1,4|1-4 指定截取的字符位置(1,4为1和4。1-4为1到4。)
cut -d : -f 1 pawwsd 显示第一个分隔符前的内容
在这里插入图片描述

cut -c 1,3 passwd 显示第一到第三字符位置的内容
在这里插入图片描述

4.sort命令

多用于字符排序
sort -n 纯数字排序
在这里插入图片描述

sort -r 倒序
在这里插入图片描述

sort -u 去掉重复数字
在这里插入图片描述

sort -o 输出到指定文件中
在这里插入图片描述

sort -t 指定分隔符
sort -k 指定要排序列

5.uniq命令

对重复字符做相应的处理
uniq -u 显示唯一的行
在这里插入图片描述

uniq -d 显示重复的行
在这里插入图片描述

uniq -c 列举出每个出现的次数,每行显示一个并统计次数。
在这里插入图片描述

6.&&和||

&&用来执行条件成立后执行的命令
||用来执行条件不成立后执行的命令
ping -c1 -w1 172.25.254.254 && echo yes || echo no ping254能通为yes,不通为no。
在这里插入图片描述

7.test命令

test命令和[]等同
rest" a &quot; = = &quot; a&quot;==&quot; a"=="b"等同[“ a &quot; = = &quot; a&quot;==&quot; a"=="b”]
test “ a &quot; = &quot; a&quot; = &quot; a"="b” && echo yes || echo no a等于b,若正确显示yes,错误显示no。
在这里插入图片描述
[“ a &quot; ! = &quot; a&quot;!=&quot; a"!="b”] 不等于
[“ a &quot; − e q &quot; a&quot;-eq&quot; a"eq"b”] 等于
[“ a &quot; − n e &quot; a&quot;-ne&quot; a"ne"b”] 不等于
[“ a &quot; − l e &quot; a&quot;-le&quot; a"le"b”] 小于等于
[“ a &quot; − l t &quot; a&quot;-lt&quot; a"lt"b”] 小于
[“ a &quot; − g e &quot; a&quot;-ge&quot; a"ge"b”] 大于等于
[“ a &quot; − g t &quot; a&quot;-gt&quot; a"gt"b”] 大于
[“ a &quot; − n e &quot; a&quot;-ne&quot; a"ne"b” -a “ a ” − g t &quot; a”-gt&quot; agt"b"] a不等于b,并且a大于b,同时成立。
[“ a &quot; − n e &quot; a&quot;-ne&quot; a"ne"b” -o “ a ” − g t &quot; a”-gt&quot; agt"b"] a不等于b,或a大于b,成立一个即可。
[-z" c &quot; ] c 为 一 个 空 的 。 [ − n &quot; c&quot;] c为一个空的。 [-n&quot; c"]c[n"c"] c是一个不是空的。
[“file1” -ef “file”] file1和file是一个文件。
[“file1” -nt “file”] file1比file新,先建立。
[“file1” -ot “file”] file1比file旧,后建立。
[-e “file”] 存不存在
[-f “file”] 为普通文件
[-L “file”] 为链接
[-S “file”] 套接字
[-d “file”] 为目录
[-c “file”] 字符设备
[-b “file”] 块设备

8.tr命令

echo hello | tr ‘a-z’ ‘A-Z’ 大小写转换
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值