Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

cleanup hdfs files owned by a user

avatar
Super Collaborator

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

1 REPLY 1

avatar
Super Guru

@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