diff
diff file file1 ##比较两个文件的不同
diff -u file file1
diff -u file file1 > file.path ##file.path为更新文件
yum install patch -y
patch file file.path ##更新file
patch -b file file.path ##更新file,并保留原文件
diff -b file file1 ##不检测空格
diff -B file file1 ##不检测空白行
diff -c file file1 ##显示具体的不同
diff -i file file1 ##不检测大小写
diff -q file file1 ##只显示是否不同
diff -r westos westos1 ##递归比较文件是否相同
cut
cut -d ##指定分隔符
cut -f 1|1,7|1-7 ##指定截取的列
cut -c 1|1,7|1-7 ##指定截取的字符
cut -d : -f 1 passwd
cut -d : -f 1,3 passwd
cut -d : -f 1-3 passwd
cut -c 2 passwd
cut -c 2,3 passwd
cut -c 2-4 passwd
sort
sort -n ##纯数字排序
sort -r ##倒序
sort -u ##去掉重复数字
sort -o ##输出到指定文件中
sort -t ##指定分隔符
sort -k ##指定要排序的列
sort westos
sort -n westos
sort -rn westos
sort -rnu westos
sort -n westos -o file
sort -rn westos |uniq -c
sort -t : -k 2 -n westos
uniq
对重复字符做相应的处理
uniq -u ##显示唯一的行
uniq -d ##显示重复的行
uniq -c ##每行显示一次并统计重复次数
sort -n file |uniq -u
sort -n file |uniq -d
sort -n file |uniq -c
&&和||
&&用来执行条件成立后执行的命令
||用来执行条件不成立后执行的命令
test命令
test命令和[ ]等同
test "$a" == "$b" 等同 [ "$a" == "$b" ]
[ "$a" = "$b" ] ##相等是为真
[ "$a" != "$b" ] ##不等时为真
[ ! "$a" = "$b" ] ##相等时为假
[ "$a" -eq "$b" ] ##相等是为真
[ "$a" -ne "$b" ] ##不等时为真
[ "$a" -gt "$b" ] ##$a大于$b时为真
[ "$a" -lt "$b" ] ##$a小于$b时为真
[ "$a" -ge "$b" ] ##$a大于等于$b时为真
[ "$a" -le "$b" ] ##$a小于等于$b时为真
[ "$a" -gt "0" -a "$a" -lt "10" ] ##$a大于0并且小于10时为真
[ "$a" -gt "0" -o "$a" -lt "10" ] ##$a大于0或者小于10时为真
[ -z "$c" ] ##字符为空时为真
[ -n "$c" ] ##字符不为空时为真
[ "file" -ef "file1" ] ##为同一个文件时为真
[ "file" -nt "file1" ] ##new
[ "file" -ot "file1" ] ##old
[ -e /mnt ] ##目录是否存在
[ -d /mnt ] ##是否为目录
[ -f /etc/passwd ] ##是否为文件
[ -L /etc/system-release ] ##是否为链接
[ -S /var/lib/mysql/mysql.sock ] ##是否为套结字
[ -b /dev/vdb ] ##是否为块设备
[ -c /dev/pts/0 ] ##是否为字符设备
tr ##替换
tr 'a-z' 'A-Z' < file