---
title: "linux locate 快速查找命令介绍"
author: "chinacode"
date: "2011-11-01T22:12:30Z"
tags: []
categories: ["操作系统"]
slug: "linux-locate"
draft: false
lastmod: "2011-11-01T22:12:30Z"
id: 1228181
url: "https://chinacode.iteye.com/blog/1228181"
---

时间过得好快，一转眼一年又快到过年了，很久没有和大家分享了，工作实在太忙了。

使用[linux](http://www.blags.org/tags/linux/ "linux")的人都会知道find查找命令。

下面有关于find的使用说明 ：[linux 查找命令大全。](http://www.blags.org/linux-find-command-daquan/ "文章链接: linux 查找命令大全")

下面给大家介绍一个快速查找工具locate，支持正则。

一般linux系统都会默认安装。没有默认安装也不要着急。

[ubuntu](http://www.blags.org/tags/ubuntu/ "ubuntu")：sudo apt-get install locate;

[centos](http://www.blags.org/tags/centos/ "centos 系统")：yum -y install mlocate;

工作原理:通过定时任务定时生成文件名相关的数据文件（一般会存放在【/var/lib/mlocate/mlocate.db】），当然定时任务不会很实时,这个会导致刚刚安装的软件找不到，这时候大家需要使用（updatedb）来更新locate数据文件。

使用方法：locate xx(要查找的文件名) -l num（要显示的行数）。当然这个文件名在系统中出现太多，就需要用到-l这个参数。不然等着刷屏吧。

正则使用参数：-r, –regexp REGEXP

Search for a basic regexp REGEXP.  No PATTERNs  are  allowed  ifthis  option  is used, but this option can be specified multiple

times.

更多使用方法：man locate；

[http://linux.about.com/od/commands/l/blcmdl1\_locate.htm](http://linux.about.com/od/commands/l/blcmdl1_locate.htm)

**出处:** [马丁博客](http://www.blags.org/)［[http://www.blags.org/](http://www.blags.org/)］

**本文链接地址:** [http://www.blags.org/linux-locate/](http://www.blags.org/linux-locate/)