Support Questions
Find answers, ask questions, and share your expertise

cleanup hdfs files owned by a user

Expert Contributor

I want to find files owned by a user in HDFS and delete all of them at once.


@Raja Sekhar Chintalapati,

The below command should do

hdfs dfs -ls -R / | awk '{ if ( $3 == "spark" && substr($0,0,1) != "d" ) { print $8 } }' | xargs hdfs dfs -rm

In the above command "spark" is the user name. Replace it with your username. Also I considered path as '/' . If you want to delete files only in a certain directory , replace it with your directory.

This will remove only the files owned by the user and not the directories.