月度热点

网络推荐



本广告位招租!

推荐给好友 上一篇 | 下一篇

如何查找并删除一个小时前创建的文件

Q.How do I find out file last modification time using a shell script or command? How do I delete or take any other custom action for all files more than one hour old in /home/ftp/incoming/raw/ directory?
$LDn:mQ"@.|BSD爱好者乐园+T0I0tME8aj9_;Y

9b/X-H$zN7]A.There are many ways (commands) to find out file modification time under UNIX / Linux operating system. You can try any one of the following command:BSD爱好者乐园(ZF y'u FQD.qyS]
find command (with -cmin switch)$ find /home/ftp/incoming/raw/ -maxdepth 1 -cmin +60 -name FileName
%OwW Y!n7w$kThe -cmin option will print FileName's status was last changed n minutes ago. This command will print all file names more than one hour old.
9OE I a~ r hstat command (with -c switch)To find time of last change as seconds since Epoch, enter:
R/z[I `fP G;X{$ stat -c %Z /path/to/fileBSD爱好者乐园"i`0yNP l
date command (with -r switch)To display the last modification time of FILE, enter:
/h/bC8j(V(s$ date -r /path/to/file
N]w}-m xiGI recommend using find command as it has -exec option to take action on all matching file such as move or delete files:
"[]&Er9y(z&L[9pwd$ find /home/ftp/incoming/raw/ -maxdepth 1 -cmin +60 -name "*" -exec /bin/rm -f {} \;
[版权声明]BSD爱好者乐园站内文章,如来源不是互联网,则均系原创或翻译之作,可随意转载,或以此为基础进行演译,但务必以链接形式注明原始出处和作者信息,否则属于侵权行为。另对本站转载他处文章,俱有说明,如有侵权请联系本人,本人将会在第一时间删除侵权文章。
TAG: 删除 查找 一小时前
 

评分:0

我来说两句

seccode