在 HDFS 中查找早于 N 天的目录 [英] Finding directories older than N days in HDFS
本文介绍了在 HDFS 中查找早于 N 天的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以使用 hadoop fs -ls 查找所有早于 N 天(从当前日期算起)的目录吗?
Can hadoop fs -ls be used to find all directories older than N days (from the current date)?
我正在尝试编写一个清理例程来查找和删除 HDFS 上的所有目录(匹配模式),这些目录是在当前日期前 N 天创建的.
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.
推荐答案
此脚本列出所有早于 [days]
的目录:
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屋!
查看全文