locate(locate)
命令用来查找文件或目录。 locate命令要比find -name
快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/mlocate/mlocate.db
。这个数据库中含有本地所有文件信息。Linux
系统自动创建这个数据库,并且每天自动更新一次,因此,我们在用whereis
和locate
查找文件时,有时会找到已经被删除的数据,或者刚刚建立文件,却无法查找到,原因就是因为数据库文件没有被更新。为了避免这种情况,可以在使用locate之前,先使用updatedb
命令,手动更新数据库。整个locate
工作其实是由四部分组成的。
//Centos > yum install mlocate -y //Ubuntu > sudo apt-get install mlocate -y
初次使用需要执行
updatedb
,不然会出现locate: can not stat ()
/var/lib/mlocate/mlocate.db’: No such file or directory`
locate [OPTION]... [PATTERN]...
pwd
相关的所有文件> locate pwd /etc/.pwd.lock /home/cpt/.local/share/fish/generated_completions/pwd.fish /home/cpt/.local/share/fish/generated_completions/pwdx.fish /root/.local/share/fish/generated_completions/pwd.fish /root/.local/share/fish/generated_completions/pwdx.fish /root/Python-3.6.4/Doc/library/pwd.rst /root/Python-3.6.4/Doc/library/spwd.rst /root/Python-3.6.4/Lib/test/test_pwd.py /root/Python-3.6.4/Lib/test/test_spwd.py /root/Python-3.6.4/Modules/pwdmodule.c /root/Python-3.6.4/Modules/pwdmodule.o /root/Python-3.6.4/Modules/spwdmodule.c /root/Python-3.6.4/Modules/clinic/pwdmodule.c.h /root/Python-3.6.4/Modules/clinic/spwdmodule.c.h /root/Python-3.6.4/build/lib.linux-x86_64-3.6/spwd.cpython-36m-x86_64-linux-gnu.so /root/Python-3.6.4/build/temp.linux-x86_64-3.6/root/Python-3.6.4/Modules/spwdmodule.o /usr/bin/pwd /usr/bin/pwdx /usr/include/pwd.h /usr/lib/golang/src/syscall/pwd_plan9.go /usr/lib/modules/3.10.0-1062.9.1.el7.x86_64/kernel/drivers/watchdog/hpwdt.ko.xz /usr/lib/modules/3.10.0-1160.11.1.el7.x86_64/kernel/drivers/watchdog/hpwdt.ko.xz /usr/lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/watchdog/hpwdt.ko.xz /usr/lib64/cracklib_dict.pwd /usr/lib64/python2.7/lib-dynload/spwdmodule.so /usr/lib64/python3.6/lib-dynload/spwd.cpython-36m-x86_64-linux-gnu.so /usr/local/python/lib/python3.6/lib-dynload/spwd.cpython-36m-x86_64-linux-gnu.so /usr/local/python/lib/python3.6/test/test_pwd.py /usr/local/python/lib/python3.6/test/test_spwd.py /usr/local/python/lib/python3.6/test/__pycache__/test_pwd.cpython-36.opt-1.pyc /usr/local/python/lib/python3.6/test/__pycache__/test_pwd.cpython-36.opt-2.pyc /usr/local/python/lib/python3.6/test/__pycache__/test_pwd.cpython-36.pyc /usr/local/python/lib/python3.6/test/__pycache__/test_spwd.cpython-36.opt-1.pyc /usr/local/python/lib/python3.6/test/__pycache__/test_spwd.cpython-36.opt-2.pyc /usr/local/python/lib/python3.6/test/__pycache__/test_spwd.cpython-36.pyc /usr/local/share/jcloud/jdog-monitor/deploy/kunlunmirror/9_de96bb875c9807de5e4a6e11fdea0b07/lib64/python3.6/lib-dynload/spwd.cpython-36m-x86_64-linux-gnu.so /usr/local/share/jcloud/jdog-monitor/deploy/kunlunmirror/9_de96bb875c9807de5e4a6e11fdea0b07/lib64/python3.6/test/test_pwd.py /usr/local/share/jcloud/jdog-monitor/deploy/kunlunmirror/9_de96bb875c9807de5e4a6e11fdea0b07/lib64/python3.6/test/test_spwd.py /usr/sbin/unix_chkpwd /usr/share/cracklib/cracklib-small.pwd /usr/share/cracklib/pw_dict.pwd /usr/share/fish/functions/__fish_pwd.fish /usr/share/fish/functions/prompt_pwd.fish /usr/share/fish/man/man1/prompt_pwd.1 /usr/share/fish/man/man1/pwd.1 /usr/share/man/man1/pwd.1.gz /usr/share/man/man1/pwdx.1.gz /usr/share/man/man8/unix_chkpwd.8.gz /usr/share/man/mann/pwd.n.gz
> locate /etc/sh /etc/shadow /etc/shadow- /etc/shells
> locate -S Database /var/lib/mlocate/mlocate.db: 289,742 directories 516,673 files 60,174,514 bytes in file names 52,034,824 bytes used to store database
> cat /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 fuse.sshfs fusectl gfs gfs2 gpfs 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 fuse.glusterfs ceph fuse.ceph" PRUNENAMES = ".git .hg .svn" PRUNEPATHS = "/afs /media /mnt /net /sfs /tmp /udev /var/cache/ccache /var/lib/yum/yumdb /var/spool/cups /var/spool/squid /var/tmp /var/lib/ceph"
原文链接:https://rumenz.com/rumenbiji/linux-locate.html
微信公众号:入门小站
linux常用命令速查手册PDF下载
3669页vim参考手册PDF下载
阿里云ECS运维Linux系统诊断PDF下载
Docker速查手册PDF下载
Linux学习笔记【强悍总结值得一看】PDF下载
shell简明教程PDF下载