Linux之locate命令

愿君学长松,慎勿作桃李。这篇文章主要讲述Linux之locate命令相关的知识,希望能为你提供帮助。
命令简介

  • /usr/bin/updatedb主要用来更新数据库,通过crontab自动完成的
  • /usr/bin/locate查询文件位置
  • /etc/updatedb.confupdatedb的配置文件
  • /var/lib/mlocate/mlocate.db存放文件信息的文件
如果系统中没有此命令
//Centos > yum install mlocate -y //Ubuntu > sudo apt-get install mlocate -y

用法
locate [OPTION]... [PATTERN]...

命令参数
  • -e将排除在寻找的范围之外。
  • -1如果 是 1.则启动安全模式。在安全模式下,使用者不会看到权限无法看到 的档案。这会使速度减慢,因为 locate 必须至实际的档案系统中取得档案的 权限资料。
  • -f将特定的档案系统排除在外,例如我们没有必要把 proc 档案系统中的档案 放在资料库中。
  • -q安静模式,不会显示任何错误讯息。
  • -n 至多显示 n个输出。
  • -r 使用正规运算式 做寻找的条件。
  • -o 指定资料库存的名称。
  • -d 指定资料库的路径
  • -h 显示辅助讯息
  • -V 显示程式的版本讯息
查找和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

搜索etc目录下所有以sh开头的文件
> locate /etc/sh /etc/shadow /etc/shadow- /etc/shells

输出locate所使用的数据库文件的相关信息,包括该数据库记录的文件/目录数量等
> 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

updatedb的配置文件/etc/updatedb.conf
> 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"

  • PRUNE_BIND_MOUNTS = " yes" #开启搜索限制
  • PRUNEFS = #搜索时不搜索的文件系统
  • PRUNENAMES = #搜索时不搜索的文件类型
  • PRUNEPATHS = 搜索时不搜索的路径
【Linux之locate命令】原文链接:https://rumenz.com/rumenbiji/linux-locate.html
微信公众号:入门小站
Linux之locate命令

文章图片

linux常用命令速查手册PDF下载
3669页vim参考手册PDF下载
阿里云ECS运维Linux系统诊断PDF下载
Docker速查手册PDF下载
Linux学习笔记【强悍总结值得一看】PDF下载
shell简明教程PDF下载

    推荐阅读