#!/bin/bash
if [ -n "$1" ] ;then
dir=$1
if [ -n "$2" ] ;then
size=$2
else
size=0
fi
echo "空白文件为:"
hadoop fs -ls -R $dir | awk '{ if ($5 <= '$size' ) print $8 }'|xargs echo
echo "准备删除文件,5秒倒计时"
time=5
while (($time >= 0 ))
do
sleep 1
echo $time
time=$(($time-1))
done
hadoop fs -ls -R $dir | awk '{ if ($5 <= '$size') print $8 }' | while read file ;do hadoop fs -rm "$file";done
sleep 1
echo "已经删除"
else
echo "请输入hdfs上需要删除空白文件的文件夹路径"
exit;
fi
借鉴博客:
awk 命令快速入门
自增或者自减