Linux中一个快速查找文件和目录的命令
功能介绍:
locate命令其实是find -name的另一种写法,但是要比后者快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/locatedb,值得注意的是:版本不同,会有所不同。有的版本位置是 /var/lib/mlocate/mlocatedb ,还有的是/var/lib/slocate/slocate.db ,这个数据库中含有本地所有文件信息。Linux系统自动创建这个数据库,并且每天自动更新一次,所以使用locate命令查不到最新变动过的文件。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。
语法格式:locate [参数] [样式]
常用参数:
-d<目录>或–database=<目录>
指定数据库所在的目录
–help
显示帮助
–version
显示版本信息
参考实例:
显示帮助 :
[root@linuxcool ~]# locate --help Usage: locate [OPTION]… [PATTERN]… Search for entries in a mlocate database. -A, --all only print entries that match all patterns -b, --basename match only the base name of path names -c, --count only print number of found entries -d, --database DBPATH use DBPATH instead of default database (which is /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 print this help -i, --ignore-case ignore case distinctions when matching patterns -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 each used database -q, --quiet report no error messages about reading databases -r, --regexp REGEXP search for basic regexp REGEXP instead of patterns --regex patterns are extended regexps -s, --stdio ignored, for backward compatibility -V, --version print version information -w, --wholename match whole path name (default) Report bugs to mitr@redhat.com.显示版本信息:[root@linuxcool ~]# locate --version mlocate 0.26 Copyright (C) 2007 Red Hat, Inc. All rights reserved. This software is distributed under the GPL v.2. This program is provided with NO WARRANTY, to the extent permitted by law.
搜索/etc目录下所有以sh开头的文件:
[root@linuxcool ~]# locate /etc/sh /etc/shadow /etc/shadow- /etc/shells
搜索/etc目录下以k开头的文件:
[root@linuxcool ~]# locate /etc/k /etc/kdump.conf /etc/kernel /etc/krb5.conf /etc/krb5.conf.d /etc/ksmtuned.conf /etc/kernel/postinst.d /etc/kernel/postinst.d/51-dracut-rescue-postinst.sh
查找和pwd相关的所有文件:
[root@linuxcool ~]# locate pwd /boot/extlinux/pwd.c32 /etc/.pwd.lock /usr/bin/pwd /usr/bin/pwdx /usr/include/pwd.h /usr/lib/modules/3.10.0-514.el7.x86_64/kernel/drivers/watchdog/hpwdt.ko /usr/lib64/cracklib_dict.pwd /usr/lib64/python2.7/lib-dynload/spwdmodule.so /usr/sbin/unix_chkpwd /usr/share/cracklib/cracklib-small.pwd /usr/share/cracklib/pw_dict.pwd /usr/share/man/man0p/pwd.h.0p.gz /usr/share/man/man1/pwd.1.gz /usr/share/man/man1/pwdx.1.gz /usr/share/man/man1p/pwd.1p.gz /usr/share/man/man3/lckpwdf.3.gz /usr/share/man/man3/ulckpwdf.3.gz /usr/share/man/man8/unix_chkpwd.8.gz /usr/share/man/overrides/de/man1/pwdx.1 /usr/share/man/overrides/fr/man1/pwdx.1 /usr/share/man/overrides/uk/man1/pwdx.1 /usr/share/syslinux/pwd.c32 /usr/src/kernels/3.10.0-514.el7.x86_64/include/config/hpwdt /usr/src/kernels/3.10.0-514.el7.x86_64/include/config/hpwdt/nmi /usr/src/kernels/3.10.0-514.el7.x86_64/include/config/hpwdt/nmi/decoding.h
Linux中一个快速查找文件和目录的命令的更多相关文章
- Linux中常用的查找文件的命令
我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索.这些是从网上找到的资料(参考资料1),因为有时很长时间不会用到,当要用的时候经常弄混了,所以放到这里方便使用. w ...
- linux中的权限对于文件和目录的重要性
对于文件 r 可以读取文件的实际内容 w 可以编辑文件的内容 x 文件可以被系统执行 对于目录 r 具有读取目录的结构列表,也就是说你可以用ls命令查看目录下的内容列表 w 可以建立新的文件,删除文件 ...
- <实训|第十一天>学习一下linux中的进程,文件查找,文件压缩与IO重定向
[root@localhost~]#序言 在今后的工作中,运维工程师每天的例行事务就是使用free -m,top,uptime,df -h...每天都要检查一下服务器,看看是否出现异常.那么今天我们就 ...
- 【收藏】linux快速查找文件的技巧
有时候,我们需要在系统中查找文件,Linux有一个非常优秀的搜寻系统. 一般提到搜寻文件的时候,很多人第一反应是find命令,但其实find不是常用的,因为速度慢,而且毁硬盘.一般我们都先用where ...
- Linux中一个文件10行内容,如何输出5-8内容到屏幕
题目是这样的,Linux中一个文件10行内容,如何输出5-8内容到屏幕首先我们模拟一下这样的环境: [root@localhost question]# pwd /root/question [roo ...
- linux查找文件或目录命令
inux查找文件或目录命令,前提:知道文件或者目录的具体名字,例如:sphinx.conf find 查找 find / -name dirname 查找目录 find -name filenam ...
- Linux基本命令(1)管理文件和目录的命令
Linux管理文件和目录的命令 命令 功能 命令 功能 pwd 显示当前目录 ls 查看目录下的内容 cd 改变所在目录 cat 显示文件的内容 grep 在文件中查找某字符 cp 复制文件 touc ...
- Linux系列教程(四)——Linux文件和目录处理命令
这个系列教程的前面我们讲解了如何安装Linux系统,以及学习Linux系统的一些方法.那么从这篇博客开始,我们就正式进入Linux命令的学习.学习命令,首先要跟大家纠正的一点就是,我们不需要记住每一条 ...
- Linux - 文件和目录常用命令
文件和目录常用命令 目标 查看目录内容 ls 切换目录 cd 创建和删除操作 touch rm mkdir 拷贝和移动文件 cp mv 查看文件内容 cat more grep 其他 echo 重定向 ...
随机推荐
- JSON.parse与JSON.stringify
JSON:JavaScript Object Notation(JavaScript对象表示法):甚至我们就可以大致认为JSON就是Javascript的对象,只不过范围小上一些. JSON的MIME ...
- Machine Learning 第三周
ML week3 逻辑回归 Logistic Function h_\theta(x)=g(\theta^Tx) g(t)=\frac{1}{1+e^{-z}} 当t大于0, 即下面公式成立时,y=1 ...
- 2018-2019-2 网络对抗技术 20165316 Exp5 MSF基础应用
2018-2019-2 网络对抗技术 20165316 Exp5 MSF基础应用 目录 原理与实践说明 实践原理 实践内容概述 基础问题回答 攻击实例 主动攻击的实践 ms08_067_netapi: ...
- 融云通信云发力教育行业 助在线教育"风口"继续腾云
4 月 16 日,2019 年AI 在线教育大会在北京站圆满落幕,会上云集超过500位资深教育从业者.200 家机构,共同就 AI 教育落地.在线教育应用经验等主题开展深入探讨.云通信领域的领导企业融 ...
- ceph rbd双挂载导致ext4文件系统inode链接数据污染
转载自:https://my.oschina.net/xueyi28/blog/1596003 ###故障现象 /data/rbd1/dir1/a/file1 /data/rbd1/dir2/a/fi ...
- ogg 12.3 for sqlserver 2016/2014 CDC模式配置
本文主要讲述ogg 12.3 通过CDC抽取mssqlserver 2016 enterprise的过程,以sqlserver为目标端投递配置相对简单,所以在此不在赘述. 针对以前的mssqlserv ...
- golang获取u盘序列号(通过读取注册表实现)
仅供参考 package main import ( "fmt" "log" "os" "strconv" " ...
- golang rc4加密
package main import "crypto/rc4" import "fmt" func main() { key := []byte(" ...
- CentOS 7编译OpenWRT
安装必要的依赖 yum install subversion binutils bzip2 gcc gcc-c++ gawk gettext flex ncurses-devel zlib-devel ...
- HL-D793G七位蓝色+PT6311驱动
和之前那块一起买的.又画了这个屏幕驱动,还画了灯丝电源驱动,和以前画的stm8核心板在JLC拼板. 亚光黑颜色,不单独收钱! 切好水洗吹干! 忘记给排针加丝印,手写代之. 焊接的时候,脑子发热,以为把 ...