码迷,mamicode.com
首页 > 其他好文 > 详细

超过N天没有访问的文件。

时间:2016-12-29 20:34:50      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:stat find


编写一个脚本,清除/aspera/home 路径下超过N天没有访问的文件。
清除的文件需要记录,并且带有文件最后的访问日期。


1、find /tmp/back/ -type f -atime +20 -exec /tmp/remov_file.bash {} \;

2、remov_file.bash

#!/bin/sh

echo $1 , `stat -c %x $1` >> /tmp/remove_file.$(date +%F).log

rm -f $1


知识点详解:

1.find 可以跟脚本。

2.stat -c %x $1  



=======================

-c  --format=FORMAT   自定义输出格式,结尾有换行

可选的文件信息输出格式
  
  %F   File type 文件类型
  %n   File name  文件名
  %s   Total size, in bytes   文件大小(单位byte)
  %u   User ID of owner  所有者的用户ID
  %U   User name of owner 所有者的用户名
  %x   Time of last access 最后访问时间



本文出自 “8277056” 博客,请务必保留此出处http://8287056.blog.51cto.com/8277056/1887395

超过N天没有访问的文件。

标签:stat find

原文地址:http://8287056.blog.51cto.com/8277056/1887395

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!