vim westos
{
hello westos
}
cat westos > westos1
{
hello westos
123
}
diff
信息输出:
[num1,num2 ] [a|c|d] [num3,num4]
num1,num2 第一个文件中的行
a 添加
c 更改
d 删除
< 第一个文件中的内容
> 第二个文件中的内容
num3,num4 第二个文件中的行
diff -x test test1
x常用参数:
-b 忽略空格
-B 忽略空行
-i 忽略大小写
-c 显示文件所有内容并标示不同
-r 对比目录
-u 合并输出
diff -u westos westos1 > westos.path 生成一个补丁
==========================================================
patch
patch 原文件 补丁文件
-b 备份原文件
patch -b westos westos.path 备份westos.path
==========================================================
cut
cut -c 1-4 passwd
cut -d : -f 1-4 passwd 第一列到第四列
-d : 指定:为分隔符
-f 指定显示的列
-c 指定截取字符
=========================================================
sort
vim westos
sort westos
sort -n westos 数字排序
sort -rn westos 倒叙
sort -run westos 去掉重复倒叙
sort -run westos -o westos1 -o 输出到指定文件
sort -t : -k 2 -n westos -t 指定分隔符 -k 指定排序的列
uniq
sort -n westos | uniq -d 显示重复的行
sort -n westos | uniq -u 显示唯一的行
sort -n westos | uniq -c 合并重复行并统计重复个数
========================================================
tr
vim westos
tr 'a-z' 'A-Z' < westos
【
HELLO WESTOS
】
tr 'a-z' 'A-Z' 小写转为大写
&& ||
ping -c1 -w1 172.25.254.104 &> /dev/null && echo yes || echo no
&& 符合条件
|| 不符合条件
==========================================================
test
用[]替换
a=1
b=1
test "$a" = "$b" && echo yes || echo no
[ "$a" = "$b" ] && echo yes || echo no
[ "$a" != "$b" ] && echo yes || echo no
a=2
[ "$a" -gt "$b" ] && echo yes || echo no -gt 大于
[ "$a" -ge "$b" ] && echo yes || echo no -ge 大于等于
[ "$a" -lt "$b" ] && echo yes || echo no -lt 小于
[ "$a" -le "$b" ] && echo yes || echo no -le 小于等于
[ "$a" -ne "$b" ] && echo yes || echo no -ne 不等于
c=4 a=2 b=10
[ "$c" -gt "$a" -a "$c" -lt "$b" ] && echo yes || echo no -a --并且
c大于a且c小于b
[ "$c" -gt "$a" -o "$c" -lt "$b" ] && echo yes || echo no -o --或
c大于a或c小于b
[ -z "$d" ] && echo no || echo yes 判定d是空字符 是就显示no,不是就显示yes
[ -n "$d" ] && echo yes || echo no 判定d不为空
文件判定
cat westos > westos1
ls
[ "westos" -ot "westos1" ] && echo yes || echo no westos比westos1老
[ "westos" -nt "westos1" ] && echo yes || echo no westos比westos1新
[ -f "westos" ] && echo yes || echo no 普通文件
[ -e "westos" ] && echo yes || echo no 存在
[ -d "/mnt" ] && echo yes || echo no 目录
ln -s /mnt/westos /mnt/test1
[ -L "test1" ] && echo yes || echo no 软连接
[ -b "/dev/vda" ] && echo yes || echo no 快设备
[ -S "" ] && echo yes || echo no 套字节
[ -c "/dev/pts/0" ] && echo yes || echo no 字符设备