find命令 — 之查找指定时间内修改过的文件

find命令 -- 之查找指定时间内修改过的文件
比如我们要查找linux下指定时间内做过改动的文件,我们可以用find命令,其实find命令的功能十分强大,下面我们通过几个简单的例子来学习下find命令的简单用法:

find /opt -iname "*" -atime 1 -type f
找出 /opt 下一天前访问过的文件
选项 OPTIONS
所有的选项都总是返回真值,它们总会被执行,除非放在表达式中执行不到的地方。因此,清楚起见,最好把它们放在表达式的开头部分。

-daystart
从当日起始时开始而不是从24小时之前,计算时间(for -amin, -atime, -cmin, -ctime, -mmin, and -mtime)。

-amin n
对文件的最近一次访问是在 n 分钟之前。

-anewer file
对文件的最近一次访问比 file 修改时间要晚。如果命令行中 -follow 在 -anewer 之前,(也只有在这种情况下 -anewer会受 -follow 的影响)。

-atime n
对文件的最近一次访问是在 n*24 小时之前。

-cmin n
对文件状态的最近一次修改是在 n 分钟之前。

-cnewer file
对文件状态的最近一次修改比 file 修改时间要晚。如果命令行中 -follow 在 -cnewer 之前,(也只有在这种情况下-cnewer 会受 -follow 的影响)。

-ctime n
对文件状态的最近一次修改是在 n*24 小时之前。

-mmin n
对文件数据的最近一次修改是在 n 分钟之前。

-mtime n
对文件数据的最近一次修改是在 n*24 小时之前。

-mtime : 指定时间曾被改动过的文件,意思是文件內容被更改过

-ctime : 指定时间曾被更改过的文件,意思是文件权限被更改过

-atime : 指定时间曾被存取过的文件,意思是文件被读取过
1.  时间是以 24 小时为一个单位,而不是以天的
2.  2011/09/08 12:00 时间开始找一天內的,会列出 2011/09/07 12:00 ~ 2011/09/08 12:00 时间內的文件

找出 3 天"以前"被改动过的文件 (前第三天以前 → 2011/09/05 12:00 以前的文件) (> 72 小时)

  1. find /var/log/ -mtime +3 -type f -print  

找出 3 天內被改动过的文件 (2011/09/05 12:00 ~ 2011/09/08 12:00 內的文件) (0 ~ 72 小时內)

  1. find /var/log/ -mtime -3 -type f -print  

找出前第 3 天被改动过的文件 (2011/09/04 12:00 ~ 2011/09/05 12:00 內的文件) (72 ~ 96 小时)

  1. find /var/log/ -mtime 3 -type f -print  

找出第 3 天被改动过的文件 (也可以这样写)

  1. find /var/log/ -mtime +2 -mtime -4 -type f -print  

( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169
Call Stack
#TimeMemoryFunctionLocation
10.0008403656{main}( ).../index.php:0
20.05411321728Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.05411321728Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.34542980128Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.34603004904Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.34673060232Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.34683077288require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.35303221376K2ControllerItem->execute( ).../k2.php:64
90.35303221376K2ControllerItem->display( ).../BaseController.php:710
100.35853490456K2ControllerItem->display( ).../item.php:78
110.35853490456K2ControllerItem->display( ).../controller.php:19
120.35983508976Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.36173529392K2ViewItem->display( ).../ViewController.php:102
140.40734117464K2ViewItem->display( ).../view.html.php:742
150.40734117464K2ViewItem->loadTemplate( ).../HtmlView.php:230
160.40964291864include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ).../HtmlView.php:701

( ! ) Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478
Call Stack
#TimeMemoryFunctionLocation
10.0008403656{main}( ).../index.php:0
20.05411321728Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.05411321728Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.34542980128Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.34603004904Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.34673060232Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.34683077288require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.35303221376K2ControllerItem->execute( ).../k2.php:64
90.35303221376K2ControllerItem->display( ).../BaseController.php:710
100.35853490456K2ControllerItem->display( ).../item.php:78
110.35853490456K2ControllerItem->display( ).../controller.php:19
120.35983508976Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.36173529392K2ViewItem->display( ).../ViewController.php:102
140.40734117464K2ViewItem->display( ).../view.html.php:742
150.40734117464K2ViewItem->loadTemplate( ).../HtmlView.php:230
160.40964291864include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ).../HtmlView.php:701
back to top