1. 程式人生 > >Linux命令之locate命令

Linux命令之locate命令

gfs2 squid utility oot locate cifs 避免 htm root

1.locate

locate 命令是文件搜索命令,它的搜索速度比 find 命令更快,原因在於它不搜索具體目錄,

而是搜索一個數據庫,這個數據庫包含本地所有文件信息。Linux系統自動創建這個數據庫,

並且每天自動更新一次,所以使用 locate 這個命令查不到最新變動過的文件。為了避免這種情況

可以在使用locate之前,先使用 updatedb 命令,手動更新數據庫。

命令格式:

locate [文件名]

#Example01 在var目錄下添加index.hml

[root@VM_81_181_centos /]# locate index.html
/usr/share/doc/HTML/index.html
/usr/share/doc/cyrus-sasl-lib-2.1.23/index.html
/usr/share/doc/db4-utils-4.7.25/utility/index.html
/usr/share/doc/gamin-0.1.10/index.html
/usr/share/doc/python-babel-0.9.4/doc/index.html
/usr/share/doc/python-babel-0.9.4/doc/api/identifier-index.html
/usr/share/doc/python-babel-0.9.4/doc/api/index.html
/usr/share/doc/python-babel-0.9.4/doc/api/since-index.html
/usr/share/doc/python-iniparse-0.3.1/index.html
/usr/share/doc/python-jinja2-2.2.1/ext/django2jinja/templates/index.html
/usr/share/doc/python-jinja2-2.2.1/html/genindex.html
/usr/share/doc/python-jinja2-2.2.1/html/index.html
/usr/share/doc/python-pygments-1.1.1/docs/build/index.html
/usr/share/doc/rsyslog-5.8.10/index.html
/usr/share/doc/udev-147/writing_udev_rules/index.html

發現並沒有搜索到/var/index.html

使用 updatedb 命令:

[root@VM_81_181_centos /]# updatedb
[root@VM_81_181_centos /]# locate index.html
/usr/share/doc/HTML/index.html
/usr/share/doc/cyrus-sasl-lib-2.1.23/index.html
/usr/share/doc/db4-utils-4.7.25/utility/index.html
/usr/share/doc/gamin-0.1.10/index.html
/usr/share/doc/python-babel-0.9.4/doc/index.html
/usr/share/doc/python-babel-0.9.4/doc/api/identifier-index.html
/usr/share/doc/python-babel-0.9.4/doc/api/index.html
/usr/share/doc/python-babel-0.9.4/doc/api/since-index.html
/usr/share/doc/python-iniparse-0.3.1/index.html
/usr/share/doc/python-jinja2-2.2.1/ext/django2jinja/templates/index.html
/usr/share/doc/python-jinja2-2.2.1/html/genindex.html
/usr/share/doc/python-jinja2-2.2.1/html/index.html
/usr/share/doc/python-pygments-1.1.1/docs/build/index.html
/usr/share/doc/rsyslog-5.8.10/index.html
/usr/share/doc/udev-147/writing_udev_rules/index.html
/var/index.html

2.當在某些目錄下創建文件,然後更新數據庫之後,並不能使用 locate 命令查找到

原因是系統在更新數據庫的配置文件中,設置了一些限制,所以,搜索不到,輸入以下命令可以看到:

[root@VM_81_181_centos lib]# vi /etc/updatedb.conf 

PRUNE_BIND_MOUNTS = "yes"
PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fusectl gfs gfs2 hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs"
PRUNENAMES = ".git .hg .svn"
PRUNEPATHS = "/afs /media /net /sfs /tmp /udev /var/cache/ccache /var/spool/cups /var/spool/squid /var/tmp"

PRUNE_BIND_MOUNTS = “yes” 表示開啟搜索限制,如果為’no’則表示不開啟搜索限制;
PRUNEFS = 表示搜索時,不搜索的文件系統;
PRUNENAMES = 表示搜索時,不搜索的文件類型;
PRUNEPATHS = 表示搜索時,不搜索的路徑;
不只locate命令遵循搜索限制,whereis與which也遵循

Linux命令之locate命令