linux命令之locate

xiaoxiao2021-02-28  116

作用:

  locate(locate) 命令用来查找文件或目录, locate命令要比find -name快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/mlocate/mlocate.dbLinux系统自动创建这个数据库,并且每天自动更新一次,因此,我们在用whereis和locate 查找文件时,有时会找到已经被删除的数据,或者刚刚建立文件,却无法查找到,原因就是因为数据库文件没有被更新。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。整个locate工作其实是由四部分组成的:

/usr/bin/updatedb   主要用来更新数据库,通过crontab自动完成的

/usr/bin/locate         查询文件位置

/etc/updatedb.conf   updatedb的配置文件

/var/lib/mlocate/mlocate.db  存放文件信息的文件

参数:

-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@cs70-moban ~]# locate cat

/usr/share/mime/application/vnd.ms-word.template.macroEnabled.12.xml /usr/share/mime/application/vnd.ms-works.xml /usr/share/mime/application/vnd.ms-wpl.xml /usr/share/mime/application/vnd.oasis.opendocument.chart-template.xml /usr/share/mime/application/vnd.oasis.opendocument.chart.xml /usr/share/mime/application/vnd.oasis.opendocument.database.xml /usr/share/mime/application/vnd.oasis.opendocument.formula-template.xml /usr/share/mime/application/vnd.oasis.opendocument.formula.xml /usr/share/mime/application/vnd.oasis.opendocument.graphics-flat-xml.xml /usr/share/mime/application/vnd.oasis.opendocument.graphics-template.xml /usr/share/mime/application/vnd.oasis.opendocument.graphics.xml /usr/share/mime/application/vnd.oasis.opendocument.image.xml /usr/share/mime/application/vnd.oasis.opendocument.presentation-flat-xml.xml /usr/share/mime/application/vnd.oasis.opendocument.presentation-template.xml /usr/share/mime/application/vnd.oasis.opendocument.presentation.xml /usr/share/mime/application/vnd.oasis.opendocument.spreadsheet-flat-xml.xml /usr/share/mime/application/vnd.oasis.opendocument.spreadsheet-template.xml /usr/share/mime/application/vnd.oasis.opendocument.spreadsheet.xml /usr/share/mime/application/vnd.oasis.opendocument.text-flat-xml.xml /usr/share/mime/application/vnd.oasis.opendocument.text-master.xml /usr/share/mime/application/vnd.oasis.opendocument.text-template.xml /usr/share/mime/application/vnd.oasis.opendocument.text-web.xml /usr/share/mime/application/vnd.oasis.opendocument.text.xml

转载请注明原文地址: https://www.6miu.com/read-32581.html

最新回复(0)