一、背景

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. vCenter orchestrator使用范例

  2. vue循环中的v-show

    v-show如果使用循环对象的属性来时控制, 这个属性必须是加载时就存在的 <div class="list-group col-sm-12" v-for="(is ...

  3. Maven构建应用程序常用配置(转)

    来自:http://shiyanjun.cn/archives/180.html 使用Maven来构建应用程序,可以非常方便地管理应用相关的资源.众所周知,应用程序中涉及到的一些依赖关系,如Java应 ...

  4. Ajax实现文件上传的临时垃圾文件回收策略

    转载请注明原文出处:http://www.cnblogs.com/ygj0930/p/6126240.html 在我们web开发过程中,一个很重要的技术就是Ajax(异步传输).Ajax通过把数据从网 ...

  5. 使用 git post-receive 钩子部署服务端代码

    在 git 中提交服务器源码的时候,如果能够直接更新到测试服务器,并且重启服务使其生效,会节省懒惰的程序员们大量的时间. git 的 Server-side hook (服务端钩子/挂钩)可以用来做件 ...

  6. linux tftp 服务

    TFTP(Trivial File Transfer Protocol)是基于UDP协议开发,用来在客户机与server之间进行简单文件传输的协议,提供不复杂.开销不大的文件传输服务. 一.改动/et ...

  7. V-rep学习笔记:力传感器

    VREP中可以添加力传感器,用于刚性连接在两个物体之间以测量这两个物体之间的作用力或力矩.如下图所示,力传感器可以测量沿着X.Y.Z三个坐标轴的力和力矩: [Forces and torques me ...

  8. django之创建第12个项目-加载图片

    百度云盘:django之创建第12个项目-加载图片 1.setting配置 #静态文件相关配置 # URL prefix for static files. # Example: "http ...

  9. Dynamic Lotusscript

    Introduction This short article gives an introduction to the underrated Execute method that is avail ...

  10. SSM框架中,配置数据库连接的问题

    MySQL数据库版本是8.0.11. 要用驱动:com.mysql.cj.jdbc.Driver 最主要的是数据库的连接url. 搞了半天才把问题搞明白: 数据库url后面要加上参数: jdbc:my ...