21.linux文件的查找

    locate 非实时查找全系统的文件,依靠一个数据库,非精确的查找

<span style="font-family:Courier New;font-size:14px;">[root@localhost bin]# locate passwd
/etc/passwd
/etc/passwd-
/etc/passwd.OLD
/etc/pam.d/passwd
/etc/security/opasswd
/lib/security/pam_passwdqc.so
/lib/security/pam_unix_passwd.so
/usr/bin/RSA_SecurID_getpasswd</span>
    有时候刚刚创建过文件,由于数据库还没有更新,需要我们手动更新
<span style="font-family:Courier New;font-size:14px;">[root@localhost bin]# updatedb</span>
    find实时查找,精确速度慢,遍历指定的目录

        格式:find 查找的路径 查找的标准 查找后的处理

        查找的路径 默认为当前的目录

        查找的标准 默认为当前路径下的所有文件

        查找后的处理 默认为打印

       

        -name FILENAME 对文件名做精确的匹配

<span style="font-family:Courier New;font-size:14px;">[root@localhost bin]# find /etc/ -name "passwd"
/etc/pam.d/passwd
/etc/passwd</span>
         文件通配符

             * 任意字符任意长度

             ? 单个任意字符

             [] 集合中的一个

         -iname 不区分大小写匹配

         -regex pattern 基于正则表达式进行文件名匹配

         -user USERNAME 基于用户名进行查找

<span style="font-family:Courier New;font-size:14px;">[root@localhost xin]# find ./ -user "xin"
./
./.bashrc
./.bash_profile
./.bash_logout
./.mozilla
./.mozilla/extensions
./.mozilla/plugins</span></span><pre name="code" class="plain">

 
         -group GROUP 基于用户组进行查找 

         -uid

         -gid

         -nouser 没有用户的文件

         -nogroup 没有用户组的文件


         -type 格局文件类型查找


         -size 根据文件的大小

              nk

              nM

              nG

         组合条件

             -o 或

             -a 与

             -not 非

[root@localhost ~]# find /tmp -nouser -a -type d
[root@localhost ~]# find /tmp -not -type d
/tmp/.font-unix/fs7100
/tmp/orbit-root/linc-24d7-0-12486249b9468
/tmp/orbit-root/linc-24d7-0-1950f57c22c71
        

         -mtime 天

         -ctime

         -atime

             [+-]n

[root@localhost ~]# find /tmp -atime +7
/tmp/vmware-config0/99-vmware-scsi-udev.rules
/tmp/mapping-root
/tmp/keyring-xD2dOV/socket
/tmp/ks-script-JxlfUE.log
         -perm MODE 根据权限来查找

               -MODE 每一位权限都被包含

               /MODE 有任何一位符合即可 

[root@localhost tmp]# find -perm 644
[root@localhost tmp]# find -perm -644
[root@localhost tmp]# find -perm /644
         处理动作

              -print 默认显示

              -ls 类似 ls -l

[root@localhost tmp]# find -perm /644 -ls
5832705    8 drwxrwxrwt  13 root     root         4096 Jan 17 04:27 .

            

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值