Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hadoop delete file which is zero byte

Tags:

zero

hdfs

I am looking for a command in hadoop 2.x to delete files which are Zero bytes in hdfs. Can any one please let me know appropriate command. I am trying to find the files that has are of zero bytes in hdfs and delete them from the directory.

like image 314
hadoopsbx Avatar asked Nov 21 '16 17:11

hadoopsbx


1 Answers

for f in $(hdfs dfs -ls -R / | awk '$1 !~ /^d/ && $5 == "0" { print $8 }'); do hdfs dfs -rm "$f"; done

Step by step:

hdfs dfs -ls -R / - list all files in HDFS recursively

awk '$1 !~ /^d/ && $5 == "0" { print $8 }') - print full path of those being not directories and with size 0

for f in $(...); do hdfs dfs -rm "$f"; done - iteratively remove

like image 77
Kombajn zbożowy Avatar answered Sep 28 '22 10:09

Kombajn zbożowy