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 the full path of those that are not directories and size 0
for f in $(...); do hdfs dfs -rm "$f"; done - iteratively delete
source
share