find
必会,参数较多
格式:find 路径 参数
主要参数:
-name 按照文件名称
-perm 按照权限来查找
-user 按照文件属主查找
-group 属组
-mtime 按照文件更改时间
-n 文件更改时间距离现在n天之内
+n 文件更改时间距离现在n天之前
-type 按照文件类型查找:d,b,f,l,c
-size 符合文件大小的文件
-exec {} \; 匹配好的参数传递其他Linux命令
find /root/ -mtime -1 #一天之内修改
find /root/ -mtime +1 #一天之前修改
find /root/ -type d
-a 与
-o 或
[root@localhost ~]# find /etc/ -size +20k -o -size -3k |wc -l #查找文件大小 大于20k 或 小于3k的文件
2517
[root@localhost ~]# find /etc/ -size -20k -a -size +3k |wc -l #查找文件大小 小于20k 且 大于3k的文件
765
[root@localhost ~]#
-exec {} \; 匹配好的内容 注入到 {}内,通过Linux其他命令来运行
[root@localhost ~]# touch {1..3}.back
[root@localhost ~]# find ./ -name "*.back" -exec ls {} \; #将find匹配的内容ls
./1.back
./2.back
./3.back
[root@localhost ~]# find ./ -name "*.back" -exec mv {} /opt/ \; #将find匹配的内容mv到/opt/
[root@localhost ~]# ls /opt/
1.back 2.back 3.back rh
| xargs -i {}
[root@localhost ~]# find ./ -name "*1.txt" |xargs -i cp {} /opt/
[root@localhost ~]# ls /opt/
1.back 1.txt 2.back 3.back parser-sha1.txt rh
-perm
查找系统中权限不低于777的危险文件
[root@localhost ~]# find /etc/ -type f -perm 777|wc -l
0
-maxdeph
查找/bin目录下的第一层目录的权限=755的文件
find /etc/ -maxdepth 1 -perm 766
-user
查找系统中所有关于用户zzp的文件,并放入/root/test
[root@localhost ~]# find / -user zzp -exec cp -a {} /root/test/ \;
[root@localhost ~]# ls -l /root/test/ |wc -l
110