如何查找在unix中最后一小时创建的文件

问题描述 投票:118回答:5

如何查找在unix中最后一小时创建的文件

unix find
5个回答
179
投票

如果要搜索的目录是srch_dir然后

$ find srch_dir -cmin -60 # change time

要么

$ find srch_dir -mmin -60 # modification time

要么

$ find srch_dir -amin -60 # access time

显示在过去一小时内创建,修改或访问的文件。

更正:ctime用于更改节点时间(不确定,请更正我)


22
投票

UNIX文件系统(通常)不存储创建时间。相反,只有访问时间,(数据)修改时间和(inode)更改时间。

话虽这么说,find-atime -mtime -ctime谓词:

$ man 1 find
...
-ctime  n
        The primary shall evaluate as true if the time of last change of
        file status information subtracted from the initialization time,
        divided by 86400 (with any remainder discarded), is n.
...

因此,find -ctime 0会在不到一小时前找到inode已更改的所有内容(例如,包括文件创建,但还会计算链接数和权限以及文件大小更改)。


10
投票

看看this link,然后帮助自己。

基本代码是

#create a temp. file
echo "hi " >  t.tmp
# set the file time to 2 hours ago
touch -t 200405121120  t.tmp 
# then check for files
find /admin//dump -type f  -newer t.tmp -print -exec ls -lt {} \; | pg

4
投票
sudo find / -Bmin 60

来自man页面:

-Bmin n

如果文件的inode创建时间与时间find之间的差异(向上舍入到下一整分钟)之间的差异为n分钟,则为真。

显然,你可能想要设置一点不同,但这个主要似乎是搜索在最后N分钟创建的任何文件的最佳解决方案。


3
投票
  • find ./-cTime -1 -type f

要么

  • 找到./-cmin -60 -type f
© www.soinside.com 2019 - 2024. All rights reserved.