当前位置: 首页> 科技> 数码 > find 命令:搜索文件

find 命令:搜索文件

时间:2025/7/17 16:10:53来源:https://blog.csdn.net/qq_38641599/article/details/142288333 浏览次数:0次

一、命令简介

find​命令的作用是搜索文件和目录。

相关命令:locate、whereis

二、命令参数

find [起始目录] [匹配模式] [条件]

选项和参数

  • -name pattern​: 根据文件名模式查找文件
  • -type type​: 根据文件类型查找文件(如f​表示普通文件,d​表示目录)
  • -exec command {} \;​: 对查找到的文件执行指定的命令
  • -size [+/-]size​: 根据文件大小查找文件(可使用c​表示字节,k​表示KB,M​表示MB)
  • -mtime n​: 根据文件修改时间查找文件(n​表示天数)
  • -delete​: 删除查找到的文件☢️

三、命令示例

  1. 按文件名查找

    find /path/to/directory -name "filename"
    
  2. 按文件类型查找

    find /path/to/directory -type f # 查找文件
    find /path/to/directory -type d # 查找目录
    
  3. 按权限查找

    find /path/to/directory -perm 644 # 查找权限为644的文件
    
  4. 按大小查找

    find /path/to/directory -size +1M # 查找大于1MB的文件
    
  5. 按时间查找

    find /path/to/directory -mtime -7 # 查找最近7天内修改过的文件
    
  6. 组合条件

    find /path/to/directory -name "*.txt" -type f -size +100k # 查找大于100KB的txt文件
    
  7. 执行操作

    find /path/to/directory -name "*.log" -exec rm {} \; # 删除所有以.log结尾的文件
    
  8. 查找目录并排除特定目录

    find /path/to/directory -type d -name "dir*" -not -path "*/dir_to_exclude/*"
    
  9. 按深度查找

    find /path/to/directory -maxdepth 2 -type f # 限制查找深度为2层
    

关键字:find 命令:搜索文件

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: