Sachin
Sachin

Reputation: 1

How to remove files inside the hadoop directory if there exists any?

I am using below command to do that. Please note this is working fine if there are any contents in that folder

hdfs dfs -rm -r /home/user/folder/*

But am getting an error when the folder is EMPTY ": No such file or directory".

My requirement is it should delete any contents if there exists. How can I achieve that ?

Upvotes: 0

Views: 2733

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191743

First run command with -test -d then && to short-circuit the rm command if it doesn't exist.

hadoop fs -test -d /home/user/folder && hadoop fs -rm -r /home/user/folder/*

Alternatively, ignore the error because the path is already deleted.

Upvotes: 1

Related Questions