23 Jul

查找某时间段修改的文件

分类:电脑技术 » linux shell   出处:本站原创         | |
需要查找某目录下某个时间段的文件,考虑到目录的特殊性(例如含有空格),做了一些特别的处理(感谢阿阿飛兄弟)

#!/bin/bash

find "$1" | while read name; do
  iname=`file "$name"|awk -F: '{print $2}'| sed -e 's/ //g'`
  if [ ! "$iname" == 'directory' ] && [ ! "$iname" == 'symbolic' ]; then
    filetime=`ls -l "$name" --time-style +%Y%m%d | awk '{print $6}'`
    if [ $2 -le $filetime ] && [ $filetime -le $3 ]; then
      echo $name
    fi
  fi
done


执行:
./findfile  /root 20080710 20080720

对于含有空格的目录如根目录下的test test
可以用./findfile  /test\ test/ 20080701 20080723 这样来执行


有任何意见欢迎提出:)
272 次阅读
0 条评论
0 条引用
不指定 作者:thatday   时间:15:47   Tags:
发表评论
  昵称 [注册]
  密码 (游客无需密码)
  网址
  电邮
高级编辑