1.为什么要有文件查找
资料很多,忘记放哪儿了,所以需要通过查找的方式进行搜索
2.Windows如何实现文件查找
计算机中的搜索框
3.Linux中如何查找文件
没有图形工具,使用命令工具搜索:find
4.find命令查找语法
| 命令 | 路径 | 选项 | 表达式 |
|---|---|---|---|
| find | [path] | [options] | [expression] |
| 查找 | 地区 | 妹纸 | 18-25岁 |
5.find查找文件的方式
(1)按照名称查找
#按名称查找
[root@peachcat1 ~]# find ./ -name "*eth0"
./ifcfg-eth0
./test-eth0
#按名称查找(不区分大小写)
[root@peachcat1 ~]# find ./ -iname "*eth0"
./ifcfg-eth0
./IFCFG-ETH0
./test-eth0
(2) 按文件大小查找 -size
#查找/etc/目录下大于5M的文件
[root@peachcat1 ~]# find /etc/ -size +5M
#查找/etc/目录下小于5M的文件
[root@peachcat1 ~]# find /etc/ -size -5M
#查找/etc/目录下等于5M的文件
[root@peachcat1 ~]# find /etc/ -size 5M
(3)按照文件类型查找 -type
f:文件
d:目录
s:套接字文件
l:链接文件
c:字符文件
b:块设备文件
(4)按照文件的更改时间 -mtime
#1.第7天
[root@peachcat ~]# find ./ -type f -mtime 7
#2.7天以前的内容都会被筛选出来,然后删除. 保留了最近7天的内容
[root@peachcat ~]# find ./ -type f -mtime +7 -name "file-*"
#3.最近7天的内容都会被筛选出来
[root@peachcat ~]# find ./ -type f -mtime -7 -name "file-*"
#4.本地文件保留最近7天的备份文件, 备份服务器保留3个月的备份文件 (实际使用方案)
find /backup/ -iname "*.bak" -mtime +7 -delete find /backup/ -iname "*.bak" -mtime +180 -delete
(5)按用户和组进行查找
-user -group -nouser -nogroup
(6)find后的处理
| 动作 | 含义 |
|---|---|
| 打印查找到的内容(默认) | |
| -ls | 以长格式显示的方式打印查找到的内容 |
| -delete | 删除查找到的文件(删除目录,仅能删除空目录) |
| -ok | 后面跟自定义的shell命令(会提示是否操作) |
| -exec | 后面跟自定义的shell命令(标准写法-exec;) |
6.其他
(1)不知道文件路径名称,只知道文件内容
[root@peachcat1 ~]# find /etc/ -type f|xargs grep "log_group"
/etc/audit/auditd.conf:log_group = root
(2)find逻辑运算符
| 符号 | 作用 |
|---|---|
| -a | 与 |
| -o | 或 |
| -not/! | 非 |