diff 命令(比对文件)
名称 | 方法 |
---|
不检查空格字符的不同 | diff -b |
不检查空白行 | diff -B |
显示全部内文,并标出不同之处 | diff -c |
不检查大小写的不同 | diff -i |
若比较的文件为 C 语言的程序码文件时,显示差异所在的函数名称 | diff -p |
仅显示有无差异,不显示详细的信息 | diff -q |
比较子目录中的文件 | diff -r |
以合并的方式来显示文件内容的不同 | diff -u |
[root@shell_jichu mnt]# vim file
[root@shell_jichu mnt]# cat file
westos hellow
text
[root@shell_jichu mnt]# vim file1
[root@shell_jichu mnt]# cat file1
westos hellow
cai
[root@shell_jichu mnt]# diff file file1
2c2
< text
---
> cai

patch命令(打补丁)
名称 | 方法 |
---|
备份每一个原始文件 | patch -b |
后面可以接“取消几层目录”的意思 | patch -p |
代表还原,将新的文件还原成原来旧的版本 | patch -R |
[root@shell_jichu mnt]# yum repolist
已加载插件:langpacks
rhel_dvd | 4.1 kB 00:00
(1/2): rhel_dvd/group_gz | 136 kB 00:00
(2/2): rhel_dvd/primary_db | 3.9 MB 00:00
源标识 源名称 状态
rhel_dvd Remote classroom copy of dvd 4,751
repolist: 4,751
[root@shell_jichu mnt]#
[root@shell_jichu mnt]# yum install patch -y
已加载插件:langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 patch.x86_64.0.2.7.1-8.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
patch x86_64 2.7.1-8.el7 rhel_dvd 110 k
事务概要
================================================================================
安装 1 软件包
总下载量:110 k
安装大小:210 k
Downloading packages:
patch-2.7.1-8.el7.x86_64.rpm | 110 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : patch-2.7.1-8.el7.x86_64 1/1
验证中 : patch-2.7.1-8.el7.x86_64 1/1
已安装:
patch.x86_64 0:2.7.1-8.el7
完毕!
[root@shell_jichu mnt]# diff -u file file1 > file.path
[root@shell_jichu mnt]# ls
file file1 file.path
[root@shell_jichu mnt]# patch -b file file.path
patching file file
[root@shell_jichu mnt]# cat file
westos hellow
cai

cut命令(截取字符)
名称 | 方法 |
---|
指定分隔符 | cut -d |
截取1和4列 | cut -f 1,4 |
指定截取的字符位置 | cut -c 1-4 |
[root@shell_jichu mnt]# cp -p /etc/passwd /mnt/passwd
[root@shell_jichu mnt]# ls
file file1 file1.rej file.orig file.path passwd
[root@shell_jichu mnt]# vim passwd
[root@shell_jichu mnt]# cut -d : -f 3 passwd
0
1
2
3
4
5
6
7
8
42
993
72
[root@shell_jichu mnt]# cut -d : -f 1-3 passwd
root:x:0
bin:x:1
daemon:x:2
adm:x:3
lp:x:4
sync:x:5
shutdown:x:6
halt:x:7
mail:x:8
gdm:x:42
gnome-initial-setup:x:993
tcpdump:x:72

sort(字符排序)
名称 | 方法 |
---|
纯数字排序 | sort -n |
倒序 | sort -r |
去掉重复数字 | sort -u |
输出到指定文件中 | sort -o |
指定要排序的列 | sort -k |
指定分隔符 | sort -t |
[root@shell_jichu mnt]# vim num
[root@shell_jichu mnt]# cat num
1
5
6
22
22
62
15
51
65
1
4
4
565
165
[root@shell_jichu mnt]# sort num
1
1
15
165
22
22
4
4
5
51
565
6
62
65
[root@shell_jichu mnt]# sort -n num
1
1
4
4
5
6
15
22
22
51
62
65
165
565
[root@shell_jichu mnt]# sort -nr num
565
165
65
62
51
22
22
15
6
5
4
4
1
1
[root@shell_jichu mnt]# sort -nru num
565
165
65
62
51
22
15
6
5
4
1

uniq(处理重复的字符)
名称 | 方法 |
---|
显示唯一的行 | uniq -u |
显示重复的行 | uniq -d |
每行显示一次并统计重复次数 | uniq -c |
每行仅显示一次,并且显示出现的次数
[root@shell_jichu mnt]# sort -n num | uniq -c
1
2 1
2 4
1 5
1 6
1 15
2 22
1 51
1 62
1 65
1 165
1 565
显示重复的行并且进行排序
[root@shell_jichu mnt]# sort -n num | uniq -d
1
4
22
显示唯一的行并且排序
[root@shell_jichu mnt]# sort -n num | uniq -u
5
6
15
51
62
65
165
565
&&命令和||命令
&&————(表示true条件为真):用来执行条件成立后执行的命令
||—————(表示false条件为假):用来执行条件不成立后执行的命令
test命令——用来检测某个条件是否成立
test "A"=="A"=="B” 等同 [ "A"=="A"=="B" ]
名称 | 方法 |
---|
相等 | [ ‘A’ = ‘B’ ] |
不相等 | [ ‘A’ != ‘B’ ] |
等于 | [ ‘A’ -eq ‘B’ ] |
不等于 | [ ‘A’ -ne ‘B’ ] |
不大于 | [ ‘A’ le ‘B’ ] |
小于 | [ ‘A’ lt ‘B’ ] |
不小于 | [ ‘A’ ge ‘B’ ] |
大于 | [ ‘A’ gt ‘B’ ] |
都满足才成立 | A -a B |
满足一个成立 | A -o B |
判断是否为空,空为真,非空为假 | -z “$A” |
和条件相反就是真,非空为真,空为假 | -n “$A” |
判断前后两个文件是否互相为硬链接 | [“file1” -ef “file2” ] |
判断前面的硬链接是否与新 | [“file1” -nt “file2” ] |
判断前面的硬链接是否旧 | [“file1” -ot “file2” ] |
判断文件是否存在 | [-e “file” ] |
判断文件是否为普通文件 | [-f “file” ] |
是否为软链接 | [-L “file” ] |
判断是否为套接字 | [-S “file” ] |
判断是否为块设备 | [-b “file” ] |
判断是否为目录 | [-d “file” ] |
判断是否为字符设备 | [-c “file” ] |
[root@shell_jichu mnt]# a=1;b=1
A等于B
[root@shell_jichu mnt]# [ “a"="a" = "a"="b” ] && echo yes || echo no
yes
A等于B
[root@shell_jichu mnt]# [ “a"−eq"a" -eq "a"−eq"b” ] && echo yes || echo no
yes
[root@shell_jichu mnt]# a=2;b=1
A不等于B
[root@shell_jichu mnt]# [ “a"!="a" != "a"!="b” ] && echo yes || echo no
yes
A不等于B
[root@shell_jichu mnt]# [ “a"−ne"a" -ne "a"−ne"b” ] && echo yes || echo no
yes
A大于等于B
[root@shell_jichu mnt]# [ “a"−ge"a" -ge "a"−ge"b” ] && echo yes || echo no
yes
A大于B
[root@shell_jichu mnt]# [ “a"−gt"a" -gt "a"−gt"b” ] && echo yes || echo no
yes
A小于等于B
[root@shell_jichu mnt]# [ “a"−le"a" -le "a"−le"b” ] && echo yes || echo no
no
A小于B A小于B
[root@shell_jichu mnt]# [ “a"−lt"a" -lt "a"−lt"b” ] && echo yes || echo no
no

tr——转换大小写
[root@shell_jichu mnt]# echo qwertyuiop | tr ‘a-z’ ‘A-Z’
QWERTYUIOP
[root@shell_jichu mnt]# echoASDFGHJKL | tr ‘a-z’ ‘A-Z’
bash: echoASDFGHJKL: 未找到命令…
[root@shell_jichu mnt]# echoASDFGHJKL | tr ‘A-Z’ ‘a-z’
bash: echoASDFGHJKL: 未找到命令…
[root@shell_jichu mnt]# echo ASDFGHJKL | tr ‘A-Z’ ‘a-z’
asdfghjkl
[root@shell_jichu mnt]# echo ASDFGHJKL | tr ‘a-z’ ‘A-Z’
ASDFGHJKL
