Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove files inside the hadoop directory at once?

Tags:

I want to remove all the files containes in hadoop directory, without removing the directory itself. I've tried using rm -r but it removed the whole directory.

like image 597
Vishal Avatar asked Aug 05 '16 20:08

Vishal


People also ask

How will remove files from HDFS recursively?

rm: Remove a file from HDFS, similar to Unix rm command. This command does not delete directories. For recursive delete, use command -rm -r .

Which method is used to delete all files in a directory?

You can use the FileUtils. cleanDirectory() method to recursively delete all files and subdirectories within a directory, without deleting the directory itself. To delete a directory recursively and everything in it, you can use the FileUtils.

What is expunge in Hadoop?

13. expunge: This command is used to empty the trash available in an HDFS system.


2 Answers

Please include a wildcard character * after the desired folder you want to delete, to avoid deleting the parent folder. Please look at the example below:

hdfs dfs -rm -r /home/user/folder/* 
like image 178
VenkateswaraCh Avatar answered Sep 20 '22 18:09

VenkateswaraCh


referring to the previous answer, you need to quote the asterisk: hdfs dfs -rm -r "/home/user/folder/*"

like image 33
rodin Avatar answered Sep 18 '22 18:09

rodin