Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

cleanup hdfs files owned by a user

Highlighted

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.

1 REPLY 1

Re: cleanup hdfs files owned by a user

@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.

Thanks,

Aditya