Linux Find 命令详情解释

文件查找

  • 普通查询
  • find /etc -maxdepth 1 -type f -name "pa*"
  • 命令 目录... 查找深度 类型 文件名称包含
    • -type文件类型:f表示文件,不指定类型的话,文件和目录都会查找

    • -maxdepth查找深度:目录层级的意思,不指定的话,就按照最大深度来查找

    • "pa*": *表示匹配任意pa开头的内容,*号还可以写在开头


按照文件大小查找

  • 按照文件大小查找(单位kMG,k要小写,MG要大写,不带单位就按照B单位来查找)
    • 1.查找大于100M的文件
      • find / - type f -size +100M [root@localhost tmp]# find / -type f -size +100M
    • 2.查找小于2k的文件
      • find /root/nginx- 1.20.2 - type f -size -2k
    • 3.查找大于50M同时小于100M的文件
      • find / - type f -size +50M - and -size -100M

忽略大小写查询

  • find /etc -maxdepth 1 -iname "pa*"
    • # i是ignore的简写,忽略的意思

根据修改时间查找文件

  • [root@localhost ~]# stat 1.txt
  • 时间参数:atime mtime ctime amin mmin cmin #(time是按照天来查找,min是按分钟查找)
    • # 时间单位为天
    • find /opt -type f -mtime -1 #-1代表一天以内,+1一天以前
  • 时间单位为分钟

  • 查找1天之前,10天之内,修改过的文件

    • [root@localhost ~]# find /etc/ -type f -mtime +1 -and -mtime -10

取反 !

  • [root@localhost ~] # find /root -type f -name "*.txt" #
    • 找名称以.txt结尾的文件
    • /root/ 1. txt /root/学习前准备.txt
  • [root@localhost ~] # find /root -type f ! -name "*.txt"
    • # 找名称中不是.txt结尾的 文件 /root/.bash_logout

用户组查找

  • 根据用户来查找文件

    • [root@localhost ~] # useradd hao
    • [root@localhost ~] # find / -user hao
  • # 查找属于hao用户的所有目录和文件

  • 根据用户组来查

    • ​​​​​​​find / -group hao

​​​​​​​


相关推荐
深紫色的三北六号9 小时前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash12 小时前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI1 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
Sinclair2 天前
简单几步,安卓手机秒变服务器,安装 CMS 程序
android·服务器
木心月转码ing2 天前
WSL+Cpp开发环境配置
linux
Rockbean3 天前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
蝎子莱莱爱打怪3 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
茶杯梦轩3 天前
CompletableFuture 在 项目实战 中 创建异步任务 的核心优势及使用场景
服务器·后端·面试
崔小汤呀3 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端