find 命令:搜索文件

一、命令简介

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层
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

灵魂信息

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值