shell (1)

#####1.diff##########################

用法:

diff [options] files | directorys

输出信息:

[num1,num2] [a|c|d] [num3,num4]

num1,num2  ##第一个文件中的行

a                    ##添加

c                    ##更改

d                    ##删除

<                    ##第一个文件中的内容

>                    ##第二个文件中的内容

num3,num4   ##第二个文件中的行

常用参数:

-b      ##忽略空格

-B      ##忽略空行

-i       ##忽略大小写

-c      ##显示文件所有内容并表示不同

-r      ##对比目录

-u      ##合并输出

[root@rhel7 mnt]# vim westos.new   ##给第一行后加空格

[root@rhel7 mnt]# diff westos westos.new

[root@rhel7 mnt]# diff -b westos westos.new

[root@rhel7 mnt]# vim westos.new

[root@rhel7 mnt]# diff -B westos westos.new

[root@rhel7 mnt]# diff -c westos westos.new

[root@rhel7 mnt]# diff -i westos westos.new

[root@rhel7 mnt]# diff -r westosdir1/ westosdir2/

[root@rhel7 mnt]# diff -u westos westos.new

#####2.patch######################

[root@rhel7 mnt]# yum install patch -y

patch     ##原文件   补丁文件

[root@rhel7 mnt]# diff -u westos westos.new > westos.path

[root@rhel7 mnt]# cat westos

[root@rhel7 mnt]# cat westos.new

[root@rhel7 mnt]# diff -u westos westos.new > westos.path

[root@rhel7 mnt]# patch westos westos.path

[root@rhel7 mnt]# cat westos

-b      ##备份原文件

[root@rhel7 mnt]# vim westos

[root@rhel7 mnt]# patch -b westos westos.path

#####3.cut#####################

[root@rhel7 mnt]# ls

[root@rhel7 mnt]# cp /etc/passwd .

cut

-d :       ##指定  :  为分隔符

-f          ##指定显示的列   5第五列    3,5 3和5列     3-5   3到5列    5-  第五列之后   -5   到第五列

-c         ##指定截取的字符 (数字用法同-f)

[root@rhel7 mnt]# cut -d : -f 1 passwd

[root@rhel7 mnt]# cut -d : -f 1,7 passwd

[root@rhel7 mnt]# cut -d : -f 1-4 passwd

[root@rhel7 mnt]# cut -d : -f 3- passwd

[root@rhel7 mnt]# cut -d : -f -3 passwd

[root@rhel7 mnt]# cut -d : -f 2-3 passwd

[root@rhel7 mnt]# cut -c 1,4 passwd

[root@rhel7 mnt]# cut -c 1-4 passwd

#####4.sort####################

[root@rhel7 mnt]# vim westos

-n     ##纯数字排序

-r     ##倒叙

-u     ##去掉重复

-o     ##输出到指定文件

-t      ##指定分隔符

-k     ##指定排序的列

[root@rhel7 mnt]# sort -n westos

[root@rhel7 mnt]# sort -rn westos

[root@rhel7 mnt]# sort -rnu westos

[root@rhel7 mnt]# sort -rnu westos -o westos1

[root@rhel7 mnt]# vim westos

[root@rhel7 mnt]# sort -t : -k 2 westos -n

#####5.unip###############

[root@rhel7 mnt]# vim westos

-c    ##合并重复并统计重复个数

-d    ##显示重复的行

-u    ##显示唯一的行

[root@rhel7 mnt]# sort -t : -k 2 westos -n | uniq -c

[root@rhel7 mnt]# sort -t : -k 2 westos -n | uniq -d

[root@rhel7 mnt]# sort -t : -k 2 westos -n | uniq -u

#####6.tr################

[root@rhel7 mnt]# vim westos

tr 'a-z' 'A-Z'    ##小写转大写

tr 'A-Z' 'a-z'   ##大写转小写

[root@rhel7 mnt]# cat westos | tr 'a-z' 'A-Z'

[root@rhel7 mnt]# cat westos | tr 'A-Z' 'a-z'

#####7.test######################

test = [ ]     ##[ ] 就相当于test命令

"test $a = $b" = [ "$a" = "$b" ]

[root@rhel7 mnt]# test "$a" = "$b" && echo yes || echo no

[root@rhel7 mnt]# [ "$a" = "$b" ] && echo yes || echo no

test数字对比:

=

!=  

-eq    ##等于

-ne    ##不等于

-le     ##小于等于

-lt      ##小于

-ge    ##大于等于

-gt     ##大于

[root@rhel7 mnt]# [ "$a" -eq "$b" ] && echo yes || echo no

[root@rhel7 mnt]# [ "$a" -ne "$b" ] && echo yes || echo no

[root@rhel7 mnt]# [ "$a" -le "$b" ] && echo yes || echo no

[root@rhel7 mnt]# [ "$a" -lt "$c" ] && echo yes || echo no

[root@rhel7 mnt]# [ "$a" -gt "$c" ] && echo yes || echo no

[root@rhel7 mnt]# [ "$a" -ge "$c" ] && echo yes || echo no

test条件关系:

-a    ##并且

-o    ##或者

[root@rhel7 mnt]# [ "$a" -gt "0" -a "$a" -le "10" ] && echo yes || echo no

[root@rhel7 mnt]# [ "$a" -lt "0" -o "$a" -gt "10" ] && echo no || echo yes

test对空的判断:

-n    ##nozero 判断内容不为空

-z    ##zero      判断内容为空

[root@rhel7 mnt]# [ -n "$a" ] && echo yes || echo no

[root@rhel7 mnt]# [ -z "$d" ] && echo yes || echo no

test对于文件的判定:

-ef    ##文件节点号是否一致(硬链)

-nt    ##文件1是不是比文件2新

-ot    ##文件1是不是比文件2老

-d     ##目录

-S     ##套结字

-L     ##软链接

-e     ##存在

-f      ##普通文件

-b     ##快设备

-c     ##字符设备

[root@rhel7 mnt]# [ "/mnt/file1" -nt "/mnt/file2" ] && echo yes || echo no

[root@rhel7 mnt]# [ "/mnt/file1" -ot "/mnt/file2" ] && echo yes || echo no

[root@rhel7 mnt]# [ "/mnt/westos" -ef "/mnt/westos1" ] && echo yes || echo no

[root@rhel7 mnt]# [ -d "/mnt/" ] && echo yes || echo no

[root@rhel7 mnt]# [ -e "/mnt/" ] && echo yes || echo no

[root@rhel7 mnt]# [ -f "/etc/passwd" ] && echo yes || echo no

[root@rhel7 mnt]# [ -L "/mnt/passwd" ] && echo yes || echo no

[root@rhel7 mnt]# [ -S "/var/lib/mysql/mysql.sock" ] && echo yes || echo no

[root@rhel7 mnt]# [ -b "/dev/nvme0n1" ] && echo yes || echo no

[root@rhel7 mnt]# [ -c "/dev/pts/0" ] && echo yes || echo no

#####8.&& || ########################

&&    ##与   符合条件作动作

||        ##非   不符合条件作动作

[root@rhel7 mnt]# ping -c1 -w1 172.25.254.222 &> /dev/null && echo yes || echo no

[root@rhel7 mnt]# ping -c1 -w1 192.168.3.9 &> /dev/null && echo yes || echo no

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值