locate 命令
part 1: 使用locate manual
$ man locate
locate(1) locate(1)
NAME
locate - find files by name
SYNOPSIS
locate [OPTION]... PATTERN...
part 2: locate 的搜索机制
whereis 严格来讲是从你环境变量的路径(path等主要路径)中查找目标。速度快,范围有限。只能用于程序名的搜索,而且只搜索二进制文件(参数-b)、man说明文件(参数-m)和源代码文件(参数-s)。如果省略参数,则返回所有信息。
举例:
$ whereis grep
grep: /bin/grep /usr/share/man/man1/grep.1.gz
$ whereis -b grep
grep: /bin/grep
$ whereis -m grep
grep: /usr/share/man/man1/grep.1.gz
$ whereis -s grep
grep:
locate则是从 updatedb命令生成的数据库中查找目标。全盘文件检索
,需要要定时运行updatedb更新数据库 ,以保证内容的实时性
举例:
$ locate xyz.py # 查找一个不出在的文件 xyz.py, 找不到结果
$ touch xyz.py # 手动建立xyz.py, 并
$ locate xyz.py # 使用 locate 查找,仍然查不到
$ sudo updatedb # 更新数据库
$ locate xyz.py # 再次locate 查找, okay
/home/jia/xyz.py
find 是“最强大,最复杂,最灵活” 的查找命令,可以用它找到任何你想找的文件
which命令的作用是,在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。也就是说,使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。
$ which find
/usr/bin/find
$ which cp
/bin/cp
$ which grep
/bin/grep
type命令其实不能算查找命令,它是用来区分某个命令到底是由shell自带的,还是由shell外部的独立二进制文件提供的。如果一个命令是外部命令,那么使用-p参数,会显示该命令的路径,相当于which命令。
$ type cd
cd is a shell builtin
$ type python
python is /usr/bin/python
$ type -p python
/usr/bin/python
$ which python
/usr/bin/python
part 3: OPTIONS
param 1:
-b, --basename
Match only the base name against the specified patterns.
This is the opposite of --wholename.
# 查询文件系统中文件名含有 pattern 的文件
$ locate -b 'ue' |less
param 2:
-c, --count
Instead of writing file names on standard output, write
the number of matching entries only.
# 查询文件系统中文件名含有 pattern 的文件的个数
$ locate -c 'ue'
param 3:
-d, --database DBPATH
Replace the default database with DBPATH. DBPATH is a
:-separated list of database file names. If more than
one --database option is specified, the resulting path is
a concatenation of the separate paths.
An empty database file name is replaced by the default
database. A database file name - refers to the standard
input. Note that a database can be read from the stan鈥?
dard input only once.
# 指定所以来的数据库的路径(一般使用缺省的数据库)
param 4:
-e, --existing
Print only entries that refer to files existing at the
time locate is run.
# 显示执行locate 命令时匹配的文件列表。
param 5:
-L, --follow
When checking whether files exist (if the --existing
option is specified), follow trailing symbolic links.
This causes broken symbolic links to be omitted from the
output.
This is the default behavior. The opposite can be speci鈥?
fied using --nofollow.
# 统计是将链接文件一并统计在内
param 6:
-i, --ignore-case
Ignore case distinctions when matching patterns.
# 进行文件名匹配时,不区分大小写
param 7:
-l, --limit, -n LIMIT
Exit successfully after finding LIMIT entries. If the
--count option is specified, the resulting count is also
limited to LIMIT.
# 进行文件名匹配时,只显示指定数目的匹配结果
param 8:
-w, --wholename
Match only the whole path name against the specified pat鈥?
terns.
This is the default behavior. The opposite can be speci鈥?
fied using --basename.
# 进行文件名匹配时,进行全名匹配。 即 locate -w 'ue' , 只会查找出文件名为 ue 的文件, 文件名中含有 ue 的将不会被统计出。
分享到:
相关推荐
linux中locate命令使用介绍.docx
Linux locate命令 Linux locate命令用于查找符合条件的文档,他会去保存文档和目录名称的数据库内,查找合乎范本样式条件的文档或目录。 一般情况我们只需要输入 locate your_file_name 即可查找指定文件。 语法 ...
主要介绍了Linux locate命令的使用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
grep more/less cat mv cp locate touch 等常用命令
Linux基础课件Linux系统文件查找locate命令共13页.pdf.zip
Linux文件搜索命令解析以及locate命令查询优化.pdf
locate命令可以在搜寻数据库时快速找到档案,数据库由updatedb程序来更新,updatedb是由cron daemon周期性建立的,这篇文章主要介绍了每天一个linux命令之locate 命令的相关资料,需要的朋友可以参考下
python写的locate的gui,locate号称是linux下的everything,但是没有图形界面,自己用python的tkinter写了一个,需要安装locate和tk库 ubuntu:sudo apt-get install locate && sudo apt-get install python-tk ...
Linux操作系统基础
linux文件名查找which,whereis,locate.docx
汉化过的增强搜索软件locate32 汉化过的增强搜索软件locate32
which,whereis,locate,find的用法与区别
linux gcc install 很全的linux gcc 安装,对离线安装gcc很有帮助...
Linux网络操作系统基础:文件命令查找文件命令locate和which.pptx
在linux中有很多查找命令,今天小编抽空给大家讲解find和locate两个命令,非常不错,具有参考借鉴价值,需要的朋友参考下吧
Can't locate ThreadQueue.pm
linux下which、whereis、locate、find命令的区别.docx
selenium+firefox在定位时遇到selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: 由于是js加载页面,想确认是否是js的原因,随后进行多次调试时发现“//div”竟然也出现了...
本文档详细介绍了在Linux系统下which、whereis、locate、find 命令的区别,具体的应用方法,结合案例,非常的实用