【Linux】find删除365天以前的文件详细解析

find . -name "*" -mtime +365 -exec rm -rf {} \;

-mtime +365  文件被修改的时间,最后一次发生到现在365天

-atime 文件被访问的时间 但是cat more less是不会改变atime的

-ctime 文件被修改的时间 如chmod 就会改变ctime


-mtime后面的时间这里用4来代替

+4 代表>=5天前  从现在再往前推5天

-4 代表<=4天内   从现在往前推4天

4  代表4-5那一天的时间


-- +4 --| 4 |------- -4 ---------
           |    |
---------|----|------------------->
7   6   5   4   3   2   1   现在


-exec  {} \   代表的是find找到文件后进行的操作命令

例如find /etc -name "passwd*" -exec grep "root" {} \;

root:x:0:0:root:/root:/bin/bash

root:x:0:0:root:/root:/bin/bash

这里是在/etc文件下找到所有passwd关键字的文件,找到后,执行grep root命令

这个{} 代表的就是find找到的所有的东西


 

posted @ 2018-09-07 10:53  zclinux  阅读(330)  评论(0)    收藏  举报