Command introduction
The locate(locate) command is used to find files or directories. The locate command is much faster than find -name because it does not search for a specific directory, but instead searches for a database, / var / lib / mlocate / mlocate db . This database contains all local file information. The Linux system automatically creates this database and updates it every day. Therefore, when we use whereis and locate to find files, we sometimes find deleted data or just created files, but we can't find them. The reason is that the database files have not been updated. To avoid this situation, you can manually update the database by using the updatedb command before using locate. The whole locate work is actually composed of four parts.
- /usr/bin/updatedb is mainly used to update the database, which is automatically completed through crontab
- /usr/bin/locate query file location
- /etc/updatedb. Configuration file for conf updatedb
- /var/lib/mlocate/mlocate.db file for storing file information
If this command is not available in the system
//Centos > yum install mlocate -y //Ubuntu > sudo apt-get install mlocate -y
For the first time, you need to execute updatedb, otherwise you will see locate: can not stat() / var / lib / mlocate / mlocate db’: No such file or directory`
usage
locate [OPTION]... [PATTERN]...
Command parameters
- -e will be excluded from the scope of the search.
- -1. If yes, start safe mode. In safe mode, users will not see files that cannot be seen by permissions. This will slow down the speed, because locate must get the permission data of the file from the actual file system.
- -f exclude specific file systems. For example, it is not necessary to put the files in the proc file system in the database.
- -q quiet mode, no error messages will be displayed.
- -n displays up to n outputs.
- -r use normal expressions to find conditions.
- -o specifies the name of the data inventory.
- -d specifies the path to the database
- -h displays auxiliary messages
- -V displays the version message of the program
Find all files related to 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
Search all files starting with sh in the etc directory
> locate /etc/sh /etc/shadow /etc/shadow- /etc/shells
Output information about the database files used by locate, including the number of files / directories recorded in the database
> 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's configuration file / 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" # turn on search restrictions
- PRUNEFS = # file systems not searched during search
- Prunnames = # file types not searched during search
- Prenepaths = path not searched when searching
Original link: https://rumenz.com/rumenbiji/linux-locate.html
WeChat official account: entry station
linux common command quick reference manual PDF download
3669 page vim reference manual PDF download
Alicloud ECS O & M Linux system diagnosis PDF download
Docker quick reference manual PDF download
Linux learning notes [strong summary worth seeing] PDF download