一、背景

Linux服务器的一个目录里,每天产生海量的文件。为了防止磁盘被写满。

决定每天删除部分老文件。OK,问题来了,如何过滤出指定日期的文件?

二、强大的Linux

一行代码搞定:

ls --full-time /recordings/ | sed -n '/2018-03-21/p'

得到的文件列表就是2018-03-21生成的文件。

三、Java示例代码

    public WavInfo getWavInfo(){
WavInfo info = new WavInfo();
List<String> list = new ArrayList<String>();
String yestoday = new DateUtil().arroundIntervalDay(new Date(), -1);
String month = yestoday.substring(0, 7);
StringBuffer cmd = new StringBuffer();
cmd.append("ls --full-time ");
cmd.append(ConfigManager.getInstance().getRecordPath());
cmd.append(month);
// cmd.append(ConfigManager.getInstance().gettMonth());
cmd.append(" | ");
cmd.append("sed -n '/");
cmd.append(yestoday);
// cmd.append(ConfigManager.getInstance().gettDay());
cmd.append("/p'");
String cmdString = cmd.toString();
logger.debug("will execute cmd : {}",cmdString);
list = new LinuxCmdUtil().executeLinuxCmd(cmdString);
// new LinuxCmdUtil().executeLinuxCmdT(cmd.toString());
if(list != null) {
// info.setPath(ConfigManager.getInstance().getRecordPath()+ConfigManager.getInstance().gettMonth());
// info.setMonth(ConfigManager.getInstance().gettMonth());
info.setPath(ConfigManager.getInstance().getRecordPath()+month);
info.setMonth(month);
info.setWavList(list);
return info;
}
return null;
}

Linux下查找指定日期的文件的更多相关文章

  1. linux下查找指定后缀的文件

    1.linux下查找指定后缀的文件 例如查找当前目录下的所有后缀名时.c或.h的文件 find  .  -type f -regex  ".*\.\(c\|h\)"

  2. linux 下查找大于100M的文件(转)

    命令行如下 find . -type f -size +1000000k Linux系统下查找大文件或目录的技巧 当硬盘空间不够时,我们就很关心哪些目录或文件比较大,看看能否干掉一些了,怎么才能知道呢 ...

  3. linux 下查找大于100M的文件

    命令行如下 find . -type f -size +100M Linux系统下查找大文件或目录的技巧 当硬盘空间不够时,我们就很关心哪些目录或文件比较大,看看能否干掉一些了,怎么才能知道呢?以易读 ...

  4. Window Linux下实现指定目录内文件变更的监控方法

    转自:http://qbaok.blog.163.com/blog/static/10129265201112302014782/ 对于监控指定目录内文件变更,window 系统提供了两个未公开API ...

  5. Linux备份-删除指定日期内文件

    #!/usr/bin/env bash source /etc/profile echo " *************** start filter ***************  &q ...

  6. [ 原创 ] Linux下查找指定类型文件以及删除

    find ./ -name "*.lok"   // 查找文件find ./ -name "*.lok" |xargs rm -fr  // 查找文件并删除

  7. linux下查找指定时间内修改过的或新建的文件

    1.简单命令 # find -type f \( -newermt '2017-04-19 00:00' -a -not -newermt '2017-04-27 23:59' \) 2.简单实现(参 ...

  8. while read line 查找指定日期的文件夹

    #!/bin/bash dir=/root/tmp targetdir=/root/tmp/tmp filenametxt=/tmp/filename.txt commandtxt=/tmp/comm ...

  9. [转帖]linux下查找文件及查找包含指定内容的文件常用命令。

    linux下查找文件及查找包含指定内容的文件常用命令. https://blog.csdn.net/yangyu19910407/article/details/18266821 最简单的查找 fin ...

随机推荐

  1. Spring boot 各种入门及问题

    Spring boot 入门 整合(完整版): https://blog.csdn.net/winter_chen001/article/details/77249029 mybatis-genera ...

  2. android中实现简单的聊天功能

    这个例子只是简单的实现了单机版的聊天功能,自己跟自己聊,啦啦~~ 主要还是展示RecyclerView控件的使用吧~ 参考我之前写的文章: android中RecyclerView控件的使用 andr ...

  3. 微信小程序 - 自定义swiper dots样式(非组件)

      自定义须知: :组件内无法使用自定义样式变化,需要自定义 :原理就是利用swiper change事件与下标index匹配,显示不同的样式 swiper组件须知: :一旦swiper用于组件化,就 ...

  4. VMware vSphere can virtualize itself + 64-bit nested guests

    Running VMware ESXi inside a virtual machine is a great way to experiment with different configurati ...

  5. C语言读取 未知长度 的矩阵

    1.确定矩阵行数: 使用每次读取一行函数fgets - row = 0; while(fgets(buf, buflen, fp) != NULL) row++; -   2.确定矩阵列数: - re ...

  6. switch omega - VNP

    文件下载 安装插件 1.Chrome地址栏输入:chrome://extensions/ 2.将附件拖入窗口,安装

  7. Nginx源代码分析—业务流程

    Nginx源代码分析-业务流程 到此为止,我们如果ngx_init_cycle已经结束.我们临时无论他做了什么,我们从他做的效果进入. 从常理上来讲,假设一个请求到达,那么我们须要接受这个请求,那么就 ...

  8. JSjs获取当前时间的前一天/后一天(昨天/明天)

    Date curDate = new Date(); var preDate = new Date(curDate.getTime() - 24*60*60*1000); //前一天 var next ...

  9. Cocos2d-js 3.0 颜色变换(调整sprite/图片的色调)

    Flash在滤镜方面做得比较成熟,starling也有很多现成的办法. 但Cocos2D这里就显得比较单薄,百度/谷歌很少相关资料. 后续如果有时间,再慢慢整理各种滤镜效果.     这里先介绍一下颜 ...

  10. VS2015安装ASP.NET MVC4

    http://www.microsoft.com/zh-cn/download/details.aspx?id=44533 下载安装 AspNetMVC4.msi