locate指令是用來找出檔案或目錄, locate指令要比【find -name】快得多,原因在於它不搜尋特定目錄,而是搜尋一個資料庫,語法是【locate [OPTION] ... [PATTERN]...】。

locate指令:
1、指令簡介
## locate (locate) 指令用來尋找檔案或目錄。 locate指令比find -name快得多,原因在於它不搜尋特定目錄,而是搜尋一個資料庫/var/lib/mlocate/mlocate.db 。這個資料庫中含有本地所有文件資訊。 Linux系統會自動建立這個資料庫,並且每天自動更新一次,因此,我們在用whereis和locate 查找文件時,有時會找到已經被刪除的數據,或者剛剛建立文件,卻無法查找到,原因就是因為資料庫文件沒有被更新。為了避免這種情況,可以在使用locate之前,先使用updatedb指令,手動更新資料庫。整個locate工作其實是由四個部分組成的:#2、用法
locate [OPTION]... [PATTERN]...
3、選項
####################################################
-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)[root@cent6 lib]# locate /etc/my /etc/my.cnf
[root@cent6 ~]# touch new.txt [root@cent6 ~]# locate new.txt [root@cent6 ~]# updatedb [root@cent6 ~]# locate new.txt /root/new.txt
[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"
以上是locate指令是什麼的詳細內容。更多資訊請關注PHP中文網其他相關文章!