Linux之find相关命令
一、find命令
1、what?
2、how?
1、参数
2、type分类
f
d
l
b
C
s
p
3、size分类
b
w
c
K
M
G
3、use
1、按名字查找
- name 与 - iname :后者不区分大小写
find / etc - name 'wkb.txt'
find / etc - iname 'wkb.txt'
find / etc - iname '*.txt'
2、按文件到大小
- size
find / etc - size + 5M
find / etc - size 5M
find / etc - size - 5M
find / etc - size 5M ls
3、指定查找目录的深度
- maxdepth
find / etc - maxdepth 5 - name 'wkb.txt'
4、按照时间查找
find / etc - mtime + 3
find / etc - mtime 3
find / etc - mtime - 3
5、查看一个文件的元数据
6、按属组查找
find / root - user alpha
find / root - group alpha2
find / root - user alpha - group alpha2
find / root - user alpha - a - group - alpha2
find / root - user salpha - o - group - alpha2
7、按文件类型查找
find / root - type f
find / root - type d
find / root - type l
find / root - type c
find / root - type b
find / root - type s
find / root - type p
8、按文件权限查找
find / root - perm - 777 - print
find / root - perm - 777 - ls
find / root - perm - 777 - ls
9、找到文件后续处理
find / root - name "wkb*" - print
find / root - name "wkb*" - ls
find / root - name "wkb*" - delete
find / root - name "wkb*" - exec rm - rf { } \;
find / root - name "wkb*" - ok cp - rvf { } / tmp \;
find / root - name "wkb*" - exec cp - rvf { } / tmp \;
10、find 与 xargs 配合使用
xargs的作用:让不支持管道的命令也可以使用管道内的内容
find / root - name "wkb*" | xargs rm - rvf
find / root - name "wkb*" | xargs - I { } cp - rf { } / tmp
find / root - name "wkb*" | xargs - I { } mv { } / tmp
find / root - name "wkb*" | xargs - I { } chmod 777 { }