搜索data目录,data目录下的结构是
110129/a.txt
110129/b.txt
110129/c.txt
……
110130/a.txt
110130/b.txt
……查找的呢15天前的文件或者文件夹并删除掉。find data -type f -name "*.txt" -exec rm -rf {} \;这条命令仅可以删除掉文件,现在要求扩充可以自动把过期的文件夹也删除掉了。

解决方案 »

  1.   

    参考:find   *   -not   -mmin   -30   -delete 这样的语句能删除30分钟以内的文件
      

  2.   

    find ./ -type f -ctime 5 -exec rm -rf {} \;
    这个脚本可以删除当天目录下5天前的文件,把这个脚本加入到crontab就可以自动运行了
    更多的参数你可以参考find的用法
      

  3.   

    find data -type d -name "*" -exec rmdir -rf {} \; 没测试不保证对的 也可以试试rmdir
      

  4.   

    find date -type f -name "*.txt" -mtime +30 -exec rm -rf{} \ ;我没有测试,楼主试试。
      

  5.   

    但是
    find date -type f 能找到文件夹吗?这个只能找到文件啊。
    其实要求就是把
    find data -type f -name "*.txt" -exec rm -rf {} \;
    find date -type d exec rm -rf () \;
    这两条命令合并起来