在HDFS中查找超过N天的目录 [英] Finding directories older than N days in HDFS

查看:128
本文介绍了在HDFS中查找超过N天的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用hadoop fs -ls查找所有超过N天(从当前日期)开始的目录吗?



我正在尝试编写一个清理例程找到并删除在当前日期前N天创建的所有HDFS目录(匹配模式)。

列出所有超过 [天] 的目录:

 # !/ bin / bash 
usage =用法:$ 0 [天数]

if [! $ 1]
然后
echo $用法
出口1
fi

现在= $(日期+%s)
hadoop fs -lsr | grep^ d|同时读f;做
dir_date =`echo $ f | awk'{print $ 6}'`
difference = $((($ now - $(date -d$ dir_date+%s))/(24 * 60 * 60)))
if [$ difference -gt $ 1];然后
echo $ f;
fi
完成


Can hadoop fs -ls be used to find all directories older than N days (from the current date)?

I am trying to write a clean up routine to find and delete all directories on HDFS (matching a pattern) which were created N days prior to the current date.

解决方案

This script lists all the directories that are older than [days] :

#!/bin/bash
usage="Usage: $0 [days]"

if [ ! "$1" ]
then
  echo $usage
  exit 1
fi

now=$(date +%s)
hadoop fs -lsr | grep "^d" | while read f; do 
  dir_date=`echo $f | awk '{print $6}'`
  difference=$(( ( $now - $(date -d "$dir_date" +%s) ) / (24 * 60 * 60 ) ))
  if [ $difference -gt $1 ]; then
    echo $f;
  fi
done

这篇关于在HDFS中查找超过N天的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆