One Linux command per day: Locate

Source: Internet
Author: User

1. Introduction to Commands

Locate (locate) command to locate a file or directory. 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 the local file information. The Linux system automatically creates this database and updates it automatically once a day, so when we use Whereis and locate to find files, we sometimes find the data that has been deleted, or just build the file, but we can't find it because the database file was not 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 made up of four parts:

    1. /usr/bin/updatedb is mainly used to update the database, through the crontab auto-completed

    2. /usr/bin/locate Querying file Locations

    3. /etc/updatedb.conf configuration files for UpdateDB

    4. /var/lib/mlocate/mlocate.db files that store file information

2. Usage
Locate [OPTION] ... [PATTERN] ...
3. Options
-B,--basenamematch only the base name of path names-C,--count only outputs the number found-D,--database DBPATH uses the database specified by DBPATH instead of the default database/var/lib/mlocate/mlocate.db-E,--existing only print entries forcurrently existing Files-L,--follow follow trailing symbolic links when checkingfileexistence (default)-H,--Help Display Assistance-I.,--ignore- CaseIgnore Case-L,--limit,-n Limit output (or counting) to LIMIT entries-M,--mmap ignored, forBackward Compatibility-P,--nofollow,-H Don'T follow trailing symbolic links when checking file existence-0, --NULLseparate entries with NUL on output-S,--statistics Don'T search for entries, print statistics about eachused database-Q,--quiet Quiet mode, no error message is displayed-R,--regexp regexp using basic regular Expressions--Regex uses an extended regular expression-S,--stdio ignored, forBackward Compatibility-V,--version displays release information-W,--wholename Match whole path name (default)
4. Example 1: Search all files in the ETC directory that start with my
Locate /etc/my/etc/my.cnf
Example 2: New files cannot be locate, using updatedb
TouchLocate~Locate  new.txt/root/new.txt
Example 3:updatedb configuration file/etc/updatedb.conf
[Email protected] ~]#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 F Usectl GFs gfs2 hugetlbfs inotifyfs iso9660 jffs2 lustre Mqueue ncpfs NFS nfs4 nfsd pipefs proc Ramfs rootfs rpc_pipefs SE CURITYFS 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"

The first line prune_bind_mounts= "yes" means: whether to restrict the search.

The second line excludes the file system types that are retrieved, that is, the file system types listed are not retrieved.

The second line indicates which suffixes are excluded from the retrieval of the file, that is, the file that is listed in the suffix of this page is skipped. The different suffixes are separated by a space.

The four rows are excluded from the retrieved path, that is, the files and subfolders under the listed path are skipped and not retrieved. updatedb After using locate still can't find the desired file

You can check if the mounted directory is ignored.

One Linux command per day: Locate

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.