linux 命令之(1) locate命令

1. NAME(名字)

locate - find files by name

定位- 通过名字查找文件。

2. SYNOPSIS (大纲)

locate [OPTION]… PATTERN…

3. DESCRIPTION (描述)

locate reads one or more databases prepared by updatedb(8) and writes file names matching at least one of the PATTERNs to standard output, one per line.

locate命令 读取 一个或者多个由 updatedb 准备好的数据库,并且 在标准输出中打印 至少一个匹配到的 一个 PATRRENs 的文件名字,每个文件名字占一行。(也就是匹配的模式可能有多个,但是只要其中一个匹配到了,就打印。)

If --regex is not specified, PATTERNs can contain globbing characters. If any PATTERN contains no globbing characters, locate behaves as if the pattern were PATTERN.

如果没有指定 --regex 选项,PATTERNs 可以包含通配符。 如果任何一个PATTERN 中都没有包含通配符,那么locate命令的行为类似于 模式为: PATTERN。( --regex 用来指定将模式解释为扩展的正则表达式。)

By default, locate does not check whether files found in database still exist (but it does require all parent directories to exist if the database was built with --require-visibility no). locate can never report files created after the most recent update of the relevant database.

默认情况下,locate命令不检查 从数据库匹配到的文件是否亦然存在(但是如果跟了–require-visibility no 选项的话,确实需要请求的父目录都存在。) locate 命令不可以报告数据库更新之后创建的文件。(也就是你创建了一个文件,但是匹配数据库没有更新,那么使用locate命令将搜索不到你刚创建的文件,只有数据库更新后,才能匹配到。)

4.EXIT STATUS(退出状态)

locate exits with status 0 if any match was found or if locate was invoked with one of the --limit 0, --help, --statistics or --version options. If no match was found or a fatal error was encountered, locate exits with status 1.

如果locate命令匹配到了或者 locate的调用 有如下选项 --limit 0, --help, --statistics ,–version ,那么locate命令将会返回0. 如果没有匹配到,或者遭遇了一个致命的错误,locate命令的退出状态将会是1.

Errors encountered while reading a database are not fatal, search continues in other specified databases, if any.

如果遭遇了一个非致命的错误,那么locate命令将会继续在别的数据库(如果存在的话)去搜寻。

5. OPTIONS (选项)

5.1 --regex

–regex
Interpret all PATTERNs as extended regexps.

将所有模式解释成扩展的正则表达式。

使用举例:

# 查找 以/home/yuanjianyu/A_Disk 开头的,以.cpp 结尾的 文件的完整路径的名字。  
locate  --regex  ^/home/yuanjianyu/A_Disk.*.cpp$

这里的.* 就是扩展的正则表达式中的统配, ^ $ 就是正则表达式中的位置铆定。

5.2 -c

-c, --count
Instead of writing file names on standard output, write the number of matching entries only.

向标准输出打印匹配到的数目,而不是 文件的名字。

5.3 -e

-e, --existing
Print only entries that refer to files existing at the time locate is run.

仅打印在locate运行时,匹配到的在文件系统中存在的文件。

5.4 -w

-w, --wholename
Match only the whole path name against the specified patterns. This is the default behavior. The opposite can be specified using --basename.

以完整路径名进行文件匹配(默认的匹配方式。) 与之相反的是 --basename, 不以完整路径名进行文件匹配。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值