侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Find命令详解整理

2023-11-04 星期六 / 0 评论 / 0 点赞 / 29 阅读 / 4239 字

Find locate 搜索命令 使用: 1 #yuminstall-ymlocate安装 updatedb 生成db数据库,服务器不建议在工作时间生成,使

Find

locate 搜索命令 使用:

1

#yum install -y mlocate   安装

updatedb  生成db数据库,服务器不建议在工作时间生成,使用计划任务在凌晨启动

1

2

3

#find /etc/ -name 'sshd*'    模糊搜索,搜索/etc目录下name为sshd的文件或目录

#find /etc/ -type d -name "sshd*"   模糊搜索,只搜索/etc目录下name为sshd的目录

#find /etc/ -type f -name "sshd*"   模糊搜索,只搜索/etc目录下name为sshd的文件

-type l 为连接文件

-type b 为block块设备

#stat 2.txt   查看 2.txt的time状态信息

参数:

atime = access time 访问时间

mtime = modify time 创建(修改)时间

ctime = change time 改动时间

更改了文件内容,ctime一定会发生改变

查看文件内容,access会发生改变

实例:

1

2

3

4

5

6

7

8

9

10

#find /etc/ -type f -mtime -1   

    #一天以内/etc目录下修改过的文件

#find /etc/ -type f -mtime +1   

    #一天前的/etc目录下修改过的文件

#find /etc/ -type f -mtime +1 -name "*.conf"     

    #一天前的/etc目录下名为.conf 且修改过的文件

#find /etc/ -type f -o -mtime +1 -o -name "*.conf"     

    #一天前的/etc目录下名为.conf 且修改过的文件      如上两个“-o”均是或的意思

#find /etc/ -type f -mmin -200    

    #200分钟以内/etc目录下修改过的文件

1

2

3

4

5

#find /etc/ -type f -mmin -200 -exec ls -l {} /;

#200分钟以内/etc目录下修改过的文件, 

-exec 是指:执行    

ls -l 命令,

{} 表示对列出的结果再次交给ls一条条的执行

1

2

3

#find /etc/ -type f -mmin -200 -exec mv {} {}.bak /;

#然后对符合条件的文件全部改名为.bak

在日常工作中会用到find去查找Size大于多少多少的文件或者目录时

1

2

#find /etc/ -type f -size -10M -exec ls -lh {} /; 

#列出来在/etc目录下 类型为文件且大于10M的 并ls -lh显示其详细信息

广告 广告

评论区