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 重定向 ...
随机推荐
- XGBoost 与 Boosted Tree
http://www.52cs.org/?p=429 作者:陈天奇,毕业于上海交通大学ACM班,现就读于华盛顿大学,从事大规模机器学习研究. 注解:truth4sex 编者按:本文是对开源xgboo ...
- Angular4 投影ngContent
- Mysql AVG() 值 返回NULL而非空结果集
[1]select 查询返回一行NULL 先来模拟复现一下遇到的问题. (1)源数据表grades,学生成绩表 (2)查询SQL语句 查询‘080601’班的各门课平均成绩 SELECT sClass ...
- MQ知识点汇总
1. MQ是什么 2. MQ能做什么 3. 消息模式 4. 使用MQ的时候需要注意什么 5. 常用MQ 6. MQ的不足 7. 什么时候不适用MQ 8. MQ的组成 9. MQ的关注点 1. MQ是什 ...
- rabbitMq及安装、fanout交换机-分发(发布/订阅)
<dependency> <groupId>com.rabbitmq</groupId> <artifactId& ...
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catchFromPBomService': Cannot create inner bean '(inner bean)#302efb82' of type [com.thinkgem.jeesite.modules.fd
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catchFromPBo ...
- linux windows 格式化一块大于2 TiB硬盘
转自:https://help.aliyun.com/document_detail/34377.html?spm=a2c4g.11186623.2.10.17447386JrLBNR#concept ...
- SHA256withRSA证书签名,私钥签名/公钥验签
证书签名 package test; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundE ...
- redis恢复(aof)
----------------redis备份恢复方法-----------------------------1.采用aof恢复方法若appendonly设置为no的情况下,在每个节点上执行bgre ...
- JS经典面试题汉诺塔
我爱撸码,撸码使我感到快乐!大家好我是Counter.今天给大家分享的是利用JS将汉诺塔原理实现出来,其实主要是考察一个递归的思想,复杂的问题简单化,汉诺塔应该都知道吧,具体的游戏规则,可以百度查查, ...