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 .