Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3387817
  • 博文数量: 631
  • 博客积分: 10716
  • 博客等级: 上将
  • 技术积分: 8397
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-01 22:35
文章分类

全部博文(631)

文章存档

2020年(2)

2019年(22)

2018年(4)

2017年(37)

2016年(22)

2015年(1)

2013年(12)

2012年(20)

2011年(19)

2010年(20)

2009年(282)

2008年(190)

分类:

2009-02-23 21:01:26

Q.How do I find out file last modification time using a 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?


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:
find command (with -cmin switch)$ find /home/ftp/incoming/raw/ -maxdepth 1 -cmin +60 -name FileName
The -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.
stat command (with -c switch)To find time of last change as seconds since Epoch, enter:
$ stat -c %Z /path/to/file
date command (with -r switch)To display the last modification time of FILE, enter:
$ date -r /path/to/file
I recommend using find command as it has -exec option to take action on all matching file such as move or delete files:
$ find /home/ftp/incoming/raw/ -maxdepth 1 -cmin +60 -name "*" -exec /bin/rm -f {} \;
阅读(4704) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~