美文网首页linux系统
linux常用命令:find精确查找

linux常用命令:find精确查找

作者: 一个小运维 | 来源:发表于2021-06-21 09:55 被阅读0次
格式:
find    [目录]   [条件1] 
  • 常用条件表示:
-type  类型(f、d、l)
-name  "文档名称"
-size  +|-文件大小(k、M、G)
-user  用户名
-mtime  修改时间

-type 类型(f文本文件、d目录、l快捷方式)

[root@A /]# find  /boot  -type  d
[root@A /]# find  /opt  -type  d
[root@A /]# find  /etc  -type  l   
[root@A /]# find  /boot  -type  f

-name "文档名称"

[root@A /]# find  /etc/  -name  "passwd"
[root@A /]# find  /etc/  -name  "*.conf"

[root@A /]# find  /etc/  -name  "*.conf"  |  wc  -l
[root@A /]# find  /etc/  -name  "*.conf"  |  cat  -n

[root@A /]# find /mnt/  -name  "nsd*"
[root@A /]# find /mnt/  -name  "nsd*"  -type d
[root@A /]# find /mnt/  -name  "nsd*"  -type f

-size +或- 文件大小(k、M、G)

[root@A /]# find  /boot/  -size  +300k
[root@A /]# find  /boot/  -size  +10M

-user 用户名 (按照数据的所有者)

[root@A /]# useradd  natasha  #创建用户
[root@A /]# find  /home/  -user  natasha
[root@A /]# find  /   -user  natasha

-mtime 修改时间 (所有的时间都是过去时间)

-mtime  +90  #90天之前的数据
-mtime  -90   #最近90天之内的数据

[root@A /]# find  /root  -mtime  +90
[root@A /]# find  /root  -mtime  -10
find高级使用
  • 处理find找到的数据,每查找的一个就传递一次
–find  [范围]  [条件]  -exec  处理命令  {}   \;
-exec额外操作的开始
{} 永远表示前面find查找的结果
\;  额外操作的结束

[root@A /]# find /boot/ -size +10M
[root@A /]# find /boot/ -size +10M -exec  cp  {}  /mnt  \;
[root@A /]# ls /mnt/
  • 查找并处理文件
    利用find查找所有用户 student 拥有的必须是文件,把它们拷贝到 /root/findfiles/ 文件夹中
[root@A /]# useradd  student      
[root@A /]# mkdir  /root/findfiles

[root@A /]# find  /  -user student  -type  f
[root@A /]# find  /  -user student  -type  f  -exec cp  {}  /root/findfiles  \;
[root@A /]# ls  -A  /root/findfiles/ 

相关文章

  • linux常用命令

    linux常用命令 文件查找 find [指定目录][指定条件][指定动作] 指定目录:​ find命令所查找的目...

  • Mac 常用操作

    一、常用命令 Linux的五个查找命令:find,locate,whereis,which,type 1、find...

  • linux find命令

    find 顾名思义就是寻找的意思,linux 下find指的是找文件 一、通过名称精确查找 二、通过名称模糊查找 ...

  • linux常用命令:find精确查找

    格式: 常用条件表示: -type 类型(f文本文件、d目录、l快捷方式) -name "文档名称" -si...

  • 服务器操作系统基础原理3—Linux2

    Linux文件和目录管理 find [路径] [参数]在硬盘中查找文件,速度较慢,必须精确匹配。 less 翻页阅...

  • 用 find 函数精确查找数据

    用 find 函数精确查找数据#### 理解时间##

  • Linux下常用命令

    很久没用linux又全忘了,这里更新自己常用命令 1.模糊查找一个文件 find . -name "*.txt" ...

  • Linux find and grep

    linux下的find文件查找命令与grep文件内容查找命令 linux下的find文件查找命令与grep文件内容...

  • Centos

    说明 1. 常用命令 1.1 查找命令对应的包,例如 netstat 1.2 查找命令 1. find find ...

  • 文件搜索命令

    文件搜索 查找需要消耗大量资源,避免在服务器高峰时查找,查找范围越小,条件越精确越好 find find 搜索范围...

网友评论

    本文标题:linux常用命令:find精确查找

    本文链接:https://www.haomeiwen.com/subject/pcoeyltx.html