Home > Article > Operation and Maintenance > What is the locate command?
The locate command is used to find files or directories. The locate command is much faster than [find -name] because it does not search a specific directory, but a database. The syntax is [locate [OPTION] ...[PATTERN]...].
locate command:
1. Command introduction
locate The (locate) command is used to find files or directories. The locate command is much faster than find -name because it does not search a specific directory, but a database /var/lib/mlocate/mlocate.db. This database contains information about all local files. The Linux system automatically creates this database and automatically updates it once a day. Therefore, when we use whereis and locate to search for files, we sometimes find data that has been deleted, or the file has just been created but cannot be found. The reason is that the database file does not have Updated. To avoid this situation, you can use the updatedb command to manually update the database before using locate. The entire locate work is actually composed of four parts:
/usr/bin/updatedb Mainly used to update the database, automatically completed through crontab
/usr/bin/locate Query file location
/etc/updatedb.conf updatedb configuration file
/var/lib/ mlocate/mlocate.db File to store file information
2. Usage
locate [OPTION]... [PATTERN]...
3.Options
-b, --basename match only the base name of path names -c, --count 只输出找到的数量 -d, --database DBPATH 使用DBPATH指定的数据库,而不是默认数据库 /var/lib/mlocate/mlocate.db -e, --existing only print entries for currently existing files -L, --follow follow trailing symbolic links when checking file existence (default) -h, --help 显示帮助 -i, --ignore-case 忽略大小写 -l, --limit, -n LIMIT limit output (or counting) to LIMIT entries -m, --mmap ignored, for backward compatibility -P, --nofollow, -H don't follow trailing symbolic links when checking file existence -0, --null separate entries with NUL on output -S, --statistics don't search for entries, print statistics about eachused database -q, --quiet 安静模式,不会显示任何错误讯息 -r, --regexp REGEXP 使用基本正则表达式 --regex 使用扩展正则表达式 -s, --stdio ignored, for backward compatibility -V, --version 显示版本信息 -w, --wholename match whole path name (default)
4. Example
Example 1: Search for all files starting with my in etc directory
[root@cent6 lib]# locate /etc/my /etc/my.cnf
Example 2: Newly added files cannot be located, use updatedb
[root@cent6 ~]# touch new.txt [root@cent6 ~]# locate new.txt [root@cent6 ~]# updatedb [root@cent6 ~]# locate new.txt /root/new.txt
Example 3: updatedb’s configuration file/etc/updatedb.conf
[root@cent6 ~]# 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 fusectl gfs gfs2 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" PRUNENAMES = ".git .hg .svn" PRUNEPATHS = "/afs /media /net /sfs /tmp /udev /var/cache/ccache /var/spool/cups /var/spool/squid /var/tmp"
Related learning recommendations: linux video tutorial
The above is the detailed content of What is the locate command?. For more information, please follow other related articles on the PHP Chinese website!