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

Ank*_*kur 125 unix find

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

小智 192

如果搜索dir是srch_dir那么无论

$ find srch_dir -cmin -60 # change time
Run Code Online (Sandbox Code Playgroud)

要么

$ find srch_dir -mmin -60 # modification time
Run Code Online (Sandbox Code Playgroud)

要么

$ find srch_dir -amin -60 # access time
Run Code Online (Sandbox Code Playgroud)

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

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

  • 诀窍是使用**负**时间值!在手册页中并不是那么明显. (10认同)
  • -cmin不是创作时间,而是改变时间!刚刚删除了我的.config dir导致在测试运行中它没有在最后X分钟更改,当我做了rm它是....所以也许编辑这个......! (3认同)
  • 这很好,但是这些标志在我正在使用的Solaris`find`中不存在.OP说Unix和我认为这些只是Linux. (2认同)

eph*_*ent 23

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已更改的所有内容(例如,包括文件创建,还计算链接计数和权限以及文件大小更改).


ayu*_*ush 10

看看这个链接,然后帮助自己.

基本代码是

#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
Run Code Online (Sandbox Code Playgroud)

  • 凉!!虽然第一个命令不是必需的.如果文件不存在,`touch`会创建文件. (4认同)
  • Ankur:它将创建一个临时文件t.tmp并将其创建时间设置为2小时...之后它将在当前目录中搜索在t.tmp之后创建的所有文件,即最后2小时. (2认同)

gwe*_*ang 6

find ./ -cTime -1 -type f

或者

find ./ -cmin -60 -type f