Linux Learning Note--locate command (File Search command)

Source: Internet
Author: User

Locate, the meaning of positioning, is to allow users to quickly search the system for the specified file.

Locate Command features:

1"locate"的速度比"find"快,因为它并不是真的查找文件,而是查数据库。2) 新建的文件,我们立即用"locate"命令去查找,一般是找不到的,   因为数据库的更新不是实时的,数据库的更新时间由系统维护。3"locate"命令所搜索的后台数据库在"/var/lib/mlocate"这个目录下,   可能有些Linux系统位置不同,具体我们可以用"locate locate"查询。4) 我们可以用"updatedb"命令来更新数据库,这样就能查询到刚才新建的文件了。5) 并不是所有的目录下的文件都会用"locate"命令搜索到,   "/etc/updatedb.conf"这个配置文件中,配置了一些"locate"命令的一些规则。

/etc/updatedb.conf configuration file parsing:

1"yes"   值为"yes"时开启搜索限制,此时,下边的配置生效;为"no"时关闭搜索限制。2) PRUNEFS =   后边跟搜索时,不搜索的文件系统。3) PRUNENAMES =    后边跟搜索时,不搜索的文件类型。4) PRUNEPATHS =    后边跟搜索时,不搜索的文件所在的路径。

1. Command format:

locate[选项] 文件名

2. Common options:

"locate -c" 查询指定文件的数目。(c为count的意思)"locate -e" 只显示当前存在的文件条目。(e为existing的意思)"locate -h" 显示"locate"命令的帮助信息。(h为help的意思)"locate -i" 查找时忽略大小写区别。(i为ignore的意思)"locate -n" 最大显示条数" 至多显示"最大显示条数"条查询到的内容。"locate -r" 使用正则运算式做寻找的条件。(r为regexp的意思)

3. Common examples:

1) 查找etc目录下所有以sh开头的文件

2) 查找etc目录下所有以sh开头的文件的数目

3) 查找etc目录下所有以sh开头的文件,并最多显示2条

4) 新建的文件,更新数据库后就能查询到了

5) 查找文件时,不区分大小写

6) 使用正则表达式,查找以akefile结尾的文件,并最多显示5条

7) 只显示当前存在的文件条目

Linux Learning Note--locate command (File Search command)

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.