欢迎来到电脑知识学习网,专业的电脑知识大全学习平台!

手机版

CentOS搜索的命令详解

操作系统 发布时间:2019-03-13 05:33:40

今天介绍 搜索的命令

windows下在找不到一下文件啊等等我们都会使用一些搜索命令,帮助自己来找到想要的东西。

linux下以及我一直写的centos下 搜索命令同样强大。

常用的有 which  whereis   locate  find

4个方法重点是放在find上面,其他命令配合使用最好。

which

这个其实前面的帖子里面也都用过,一般是针对可执行命令,which比较多。

一般使用which 使用范围比较局限 /PATH 下  ,可执行的二进制命令 都是他的搜索范围。

whereis 

属于不精确搜索,具备搜索命令但是范围也是局限,一般在/bin、/usr/share 

locate 

这个命令不能直接使用,需要安装依赖的包

yum install -y mlocate

CentOS,搜索命令

and

使用前记得 updatedb 同步一下这个命令依赖的数据库文件,否者不会有任何结果。

                           find

终于开始关键点了。

    find  范围  -type  f   搜索指定范围下的普通文件  type代表文件类型

    find  范围  -type  d   搜索指定范围下的目录文件  type代表文件类型

看实例

CentOS,搜索命令

可以精确搜索 指定你要找的文件名

find /tmp -name “123”或者 find /tmp -name "1*"

看实例

CentOS,搜索命令

第二个命令 “1*”  *通配含义

还可以根据linux 文件上的 三个time 来进行匹配的搜索

三个time

atime  access time 访问时间

ctime  是更改文件inode信息的time 或者叫更改文件属性的time

mtime  是更改文件内容的time

eg 

find /root -name "*txt" -mtime  +5  搜索在5天前建立的文件 

find /root -name "*txt" -mtime  -5  搜索在5天内建立的文件

如果是搜索一个小时 使用 mmin

find /root -name "*txt" -mtime  -60 

还可以使用管道符 | 连用xargs  这样用

find /tmp -name "1*" -mtime -1 |xargs ls -l

CentOS,搜索命令

查看三个time可以使用stat  为了更好理解三个time 注意看下图 1----2----3 三个time变化

CentOS,搜索命令

echo 影响了 mtime 与 ctime 

touch 影响了三个 time


责任编辑:电脑知识学习网

操作系统