Linux中的find小白操作

find 搜索命令

Linux find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。
## 一、语法

find [path...] [options]  [expression] [action]
命令         路径     选项      表达式         动作

1.按文件名查找:

[root@hero ~]# find     /etc      -name     "hosts"   // 按名字查找
[root@hero ~]# find    /etc      -iname     "hosts"   // 不区分大小
[root@hero ~]# find    /etc      -iname      "hos*"   // 模糊查找

-i可以忽略大小写

成功输出

/etc/hosts

成功文件查找

2.按文件大小查找:

[root@hero ~]# find /etc -size   +*M   // 大于5M的文件
[root@hero ~]# find /etc -size   *M     // 5M的文件
[root@hero ~]# find /etc -size  -*M    // 小于5M的文件

3.指定查找的目录深度:

[root@hero ~]# find / -maxdepth 3 -a -name "ifcfg-en*"   // 在3级目录下查找"ifcfg-en*"
[root@hero ~]# find / -maxdepth 4 -a -name "ifcfg-en*"  //  在4级目录下查找"ifcfg-en*"

4.按文件属组、属主查找:

[root@hero ~]# find /home -user * //属主是*的文件
[root@hero ~]# find /home -group * //属组是*组的文件

5.按文件类型查找:

[root@hero ~]# find /tmp -type f    // 查普通文件
[root@hero ~]# find /dev -type b    //b=block

6.按文件权限查找:

[root@hero ~]# find . -perm 604 -ls   //查找权限为604的文件、目录

7.找到后处理的动作 ACTIONS:

[root@hero ~]# find /etc -name "775*" -delete  // 查找系统中名为755的文件和目录,删除
[root@hero ~]# find /etc -name "ifcfg*" -ok cp -rvf {} /tmp \  //  查找到“ifcfg”后复制到/tmp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值