locate

查找文件.

语法

  locate [options] pattern

选项

-d path, --database=path
            指定数据库所在的目录.

-h, --help   打印帮助信息并退出

--version   印版本信息然后退出

搜索文件名和打印匹配的数据库. *, ?, [, and ] 是专门处理的; / and . are not.

匹配包括包含模式的所有文件,除非模式包含元字符,在这种情况下,locate需要完全匹配。

如果locate不起作用,请运行命令:slocate -u以重建索引

更快的搜索
在现代硬件上,创建和搜索所有文件名的未压缩索引文件通常比使用压缩的定位数据库更快

   sudo find / > database.txt
   grep Alanis database.txt

实例

搜索etc目录下所有以sh开头的文件

locate /etc/sh

搜索用户主目录下,所有以m开头的文件

locate ~/m

搜索用户主目录下,所有以m开头的文件,并且忽略大小写

locate ~/m

locate 命令实例:

linux命令:locate -b'\ domain-list.txt' domain-list.txt' -b'\ locate locate -b'\ domain-list.txt'rootopen.com
linux命令:locate -b'\ domain-list.txt' domain-list.txt' -b'\ locate locate -b'\ domain-list.txt'rootopen.com
2018-09-11 09:55:30

linux命令:locate file1 dir1 dir1 file1 locate locate file1 dir1rootopen.com
linux命令:locate file1 dir1 dir1 file1 locate locate file1 dir1rootopen.com
2018-08-15 20:47:56

linux命令:locate searchstring | xargs ls -l -l ls xargs | searchstring locate locate searchstring | xargs ls -lrootopen.com
linux命令:locate searchstring | xargs ls -l -l ls xargs | searchstring locate locate searchstring | xargs ls -lrootopen.com
2018-04-03 10:25:48

linux命令:locate searchstring | xargs grep foo foo grep xargs | searchstring locate locate searchstring | xargs grep foorootopen.com
linux命令:locate searchstring | xargs grep foo foo grep xargs | searchstring locate locate searchstring | xargs grep foorootopen.com
2018-01-18 23:54:48

linux命令:locate -e somefile | xargs ls -l -l ls xargs | somefile -e locate locate -e somefile | xargs ls -lrootopen.com
linux命令:locate -e somefile | xargs ls -l -l ls xargs | somefile -e locate locate -e somefile | xargs ls -lrootopen.com
2018-02-27 03:40:48

linux命令:locate -S -S locate locate -Srootopen.com
linux命令:locate -S -S locate locate -Srootopen.com
2018-02-16 07:18:48

linux命令:locate munin | xargs rm -r -r rm xargs | munin locate locate munin | xargs rm -rrootopen.com
linux命令:locate munin | xargs rm -r -r rm xargs | munin locate locate munin | xargs rm -rrootopen.com
2018-03-28 11:26:48

linux命令:locate -i yourfilename | sed 's/ /\\ /g' | xargs ls -lah | less less | -lah ls xargs | /g' /\\ 's/ sed | yourfilename -i locate locate -i yourfilename | sed 's/ /\\ /g' | xargs ls -lah | lessrootopen.com
linux命令:locate -i yourfilename | sed 's/ /\\ /g' | xargs ls -lah | less less | -lah ls xargs | /g' /\\ 's/ sed | yourfilename -i locate locate -i yourfilename | sed 's/ /\\ /g' | xargs ls -lah | lessrootopen.com
2018-01-21 21:47:48

linux命令:locate *\\.php|xargs grep --color=always -i -5 "namespace\s.*\W"|less "namespace\s.*\W"|less -5 -i --color=always grep *\\.php|xargs locate locate *\\.php|xargs grep --color=always -i -5 "namespace\s.*\W"|lessrootopen.com
linux命令:locate *\\.php|xargs grep --color=always -i -5 "namespace\s.*\W"|less "namespace\s.*\W"|less -5 -i --color=always grep *\\.php|xargs locate locate *\\.php|xargs grep --color=always -i -5 "namespace\s.*\W"|lessrootopen.com
2018-02-10 01:51:48

linux命令:locate -0 -i *barthes* | xargs -0 mv -t ~/'Library/Books/Barthes, Roland' Roland' ~/'Library/Books/Barthes, -t mv -0 xargs | *barthes* -i -0 locate locate -0 -i *barthes* | xargs -0 mv -t ~/'Library/Books/Barthes, Roland'rootopen.com
linux命令:locate -0 -i *barthes* | xargs -0 mv -t ~/'Library/Books/Barthes, Roland' Roland' ~/'Library/Books/Barthes, -t mv -0 xargs | *barthes* -i -0 locate locate -0 -i *barthes* | xargs -0 mv -t ~/'Library/Books/Barthes, Roland'rootopen.com
2018-04-17 12:55:48

linux命令:locate -i /pattern/ | xargs -n1 dirname | sort -u -u sort | dirname -n1 xargs | /pattern/ -i locate locate -i /pattern/ | xargs -n1 dirname | sort -urootopen.com
linux命令:locate -i /pattern/ | xargs -n1 dirname | sort -u -u sort | dirname -n1 xargs | /pattern/ -i locate locate -i /pattern/ | xargs -n1 dirname | sort -urootopen.com
2018-03-24 18:10:48

Linux的Bash命令行(A-Z排序)