命令用途
locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案。
其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了。
所以你要知道:
1. locate的速度比find快,因为它并不是真的查找文件,而是查数据库
2. locate的查找并不是实时的,而是以数据库的更新为准,一般是系统自己维护
3. 升级数据库命令:locate -- u
命令用法
#查看locate版本信息-V
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ locate -V
- mlocate 0.25
- Copyright (C) 2007 Red Hat, Inc. 保留所有权利。
- 本软件在 GPL v.2 下发布。
-
- 本程序不提供任何担保,在法法律允许的范围内予以排除。
#查看locate帮助信息
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ locate -h
- 用法: locate [OPTION]... [PATTERN]...
- 在mlocate数据库中搜索条目.
-
- -b, --basename 匹配唯一的路径名称的基本文件名
- -c, --count 只显示找到条目的号码
- -d, --database DBPATH 用 DBPATH 替代默认的数据库(/var/lib/mlocate/mlocate.db)
- -e, --existing 只显示当前存在的文件条目
- -L, --follow 当文件存在时跟随蔓延的符号链接 (默认)
- -h, --help 显示本帮助
- -i, --ignore-case 匹配模式时忽略大小写区别
- -l, --limit, -n LIMIT 限制为 LIMIT项目的输出 (或 计数)
- -m, --mmap 忽略向后兼容性
- -P, --nofollow, -H 当检查文件时不跟随蔓延的符号
- 链接
- -0, --null 输出时以 NUL 分隔项目
- -S, --statistics 不搜索项目,显示有关每个已用数据库的统计信息
- -q, --quiet 不报告关于读取数据库的错误消息
- -r, --regexp REGEXP 搜索基本正则表达式 REGEXP 来代替模式
- --regex 模式是扩展正则表达式
- -s, --stdio 忽略向后兼容性
- -V, --version 显示版本信息
- -w, --wholename 匹配完整路径名 (默认)
-
- 将 bug 报告给 mitr@redhat.com.
# 查找etc目录下所有以sh开头的文件
#查看soft目录下以android开头的文件,限定只显示5个,使用 -n
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ locate -n 5 /soft/android
- /home/bixiaopeng/soft/android-studio
- /home/bixiaopeng/soft/android-studio-bundle-130.737825-linux.tgz
- /home/bixiaopeng/soft/android-studio/Install-Linux-tar.txt
- /home/bixiaopeng/soft/android-studio/LICENSE.txt
- /home/bixiaopeng/soft/android-studio/NOTICE.txt
#查找时区分大小写
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ locate makefile
- /usr/share/doc/python3-uno/demo/makefile.mk
- /usr/share/emacs/23.4/lisp/cedet/ede/makefile-edit.elc
- /usr/share/gtksourceview-3.0/language-specs/makefile.lang
- /usr/share/icons/Humanity/mimes/16/gnome-mime-text-x-makefile.svg
- /usr/share/icons/Humanity/mimes/22/gnome-mime-text-x-makefile.svg
-
- .....
#查找时不区分大小写,使用 -i
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ locate -i makefile
-
- /usr/src/linux-headers-3.8.0-30/kernel/Makefile
- /usr/src/linux-headers-3.8.0-30/kernel/debug/Makefile
- /usr/src/linux-headers-3.8.0-30/kernel/debug/kdb/Makefile
- /usr/src/linux-headers-3.8.0-30/kernel/events/Makefile
-
- ......
# ------------- 使用正规运算式 做查找的条件 locate -r
#查找以makefile结尾的文件
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ locate -r makefile$
- /usr/src/linux-headers-3.8.0-19/scripts/mkmakefile
- /usr/src/linux-headers-3.8.0-19-generic/scripts/mkmakefile
- /usr/src/linux-headers-3.8.0-27/scripts/mkmakefile
- /usr/src/linux-headers-3.8.0-27-generic/scripts/mkmakefile
- /usr/src/linux-headers-3.8.0-29/scripts/mkmakefile
- /usr/src/linux-headers-3.8.0-29-generic/scripts/mkmakefile
- /usr/src/linux-headers-3.8.0-30/scripts/mkmakefile
- /usr/src/linux-headers-3.8.0-30-generic/scripts/mkmakefile
#查找以/var/lib/dpkg/info/开头的文件
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ locate -r ^/var/lib/dpkg/info/
-
- /var/lib/dpkg/info/zlib1g:amd64.postinst
- /var/lib/dpkg/info/zlib1g:amd64.postrm
- /var/lib/dpkg/info/zlib1g:amd64.shlibs
- /var/lib/dpkg/info/zlib1g:amd64.symbols
- /var/lib/dpkg/info/zlib1g:i386.list
- /var/lib/dpkg/info/zlib1g:i386.md5sums
- /var/lib/dpkg/info/zlib1g:i386.postinst
- /var/lib/dpkg/info/zlib1g:i386.postrm
- /var/lib/dpkg/info/zlib1g:i386.shlibs
- /var/lib/dpkg/info/zlib1g:i386.symbols
