如何在unix中查找在过去一小时内创建的文件

nle07wnf  于 2023-01-13  发布在  Unix
关注(0)|答案(6)|浏览(555)

如何在unix中查找在过去一小时内创建的文件

mefy6pfw

mefy6pfw1#

如果要搜索的目录为srch_dir,则

$ find srch_dir -cmin -60 # change time

$ find srch_dir -mmin -60 # modification time

$ find srch_dir -amin -60 # access time

显示了在过去一小时内分别更改了元数据(ctime)、修改了文件内容(mtime)或访问了文件内容(atime)的文件。
ctime并非不直观,需要进一步解释:
ctime:与mtime只与文件内容有关不同,changed timestamp表示文件的某些元数据最后一次发生变化的时间,ctime表示文件的元数据最后一次发生变化的时间,例如,如果文件的权限设置发生了变化,ctime会指示。

eiee3dmh

eiee3dmh2#

UNIX文件系统(通常)不存储创建时间,而只有访问时间、(数据)修改时间和(信息节点)更改时间。
也就是说,find具有-atime-mtime-ctime predicate :

$ man 1  [find](http://pubs.opengroup.org/onlinepubs/009695399/utilities/find.html) 
...
**-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在不到一小时前发生更改的所有内容(例如,包括文件创建,但也计算链接计数、权限和文件大小更改)。

n7taea2i

n7taea2i3#

看看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
icnyk63a

icnyk63a4#

find ./ -cTime -1 -type f

find ./ -cmin -60 -type f

gopyfrb3

gopyfrb35#

sudo find / -Bmin 60

man页面:

  • 最小体重n
    如果文件的inode创建时间与find启动时间之间的差值(向上舍入到下一整分钟)为n分钟,则为True。
    显然,您可能希望设置得稍有不同,但对于搜索最近 N 分钟内创建的任何文件,此主文件似乎是最佳解决方案。
v1l68za4

v1l68za46#

查看link了解更多详情。
要在当前目录中查找最近一小时内创建的文件,可以使用-amin
发现-胺-60 -F型
这将查找在过去1小时内创建的文件。

相关问题