简体   繁体   English

如何从 HDFS 中的目录结构中删除所有文件?

[英]how to delete all files from a directory structure in a HDFS?

I am looking to clean up the environment.我正在寻找清理环境。 I want to execute the following command recursively, witout hard coding for each sub folder.我想递归地执行以下命令,而不对每个子文件夹进行硬编码。 As I have hundreds of subfolder in a HDFS directory.因为我在 HDFS 目录中有数百个子文件夹。

hadoop fs -rm -r /a/b1/c1/d1.txt

hadoop fs -rm -r /a/b2/c2/d2.txt

hadoop fs -rm -r /a/b3/c3/d3.txt

hadoop fs -rm -r /a/bn/cn/dn.txt

I want to delete all the files but not the directory or the sub-directories.我想删除所有文件,但不删除目录或子目录。 I am not sure how to use a recursive command to keep the directory structure in HDFS while delete all the files in it.我不确定如何使用递归命令将目录结构保留在 HDFS 中,同时删除其中的所有文件。

hadoop fs -ls -R /directory/structure/ | grep "\.json" | awk '{print $8}' | xargs -I{} hadoop fs -rm "{}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM