- Published on
locate command-quickly find files or directories
Jonas
The locate command is actually another way of writing find -name, but it is much faster than the latter, because it does not search a specific directory, but a database /var/lib/locatedb. It is worth noting that the version is different Will be different. Some version locations are /var/lib/mlocate/mlocatedb, and others are /var/lib/slocate/slocate.db, this database contains all local file information.
The Linux system automatically creates this database and updates it once a day, so the latest changed files cannot be found using the locate command. In order to avoid this situation, you can use the updatedb command to manually update the database before using locate.
Syntax: locate [parameter] [file]
Command parameters
-d<directory> or --database=<directory> | Specify the directory where the database is located |
--help | Show help |
--version | Display version information |
Reference example
Search for all files beginning with sh in the /etc directory:
[root@linuxstar ~]# locate /etc/sh /etc/shadow /etc/shadow- /etc/shells
Search for files starting with k in the /etc directory:
[root@linuxstar ~]# locate /etc/k /etc/kdump.conf /etc/kernel /etc/krb5.conf /etc/krb5.conf.d /etc/ksmtuned.conf /etc/kernel/postinst.d /etc/kernel/postinst.d/51-dracut-rescue-postinst.sh
Find all files related to pwd:
[root@linuxstar ~]# locate pwd /boot/extlinux/pwd.c32 /etc/.pwd.lock /usr/bin/pwd /usr/bin/pwdx /usr/include/pwd.h