Deleting file/folder from Hadoop
When you say delete from Hadoop, you really mean delete from HDFS.
To delete something from HDFS do one of the two
From the command line:
- deprecated way:
hadoop dfs -rmr hdfs://path/to/file
- new way (with hadoop 2.4.1) :
hdfs dfs -rm -r hdfs://path/to/file
Or from java:
FileSystem fs = FileSystem.get(getConf());fs.delete(new Path("path/to/file"), true); // delete file, true for recursive
To delete a file from hdfs you can use below given command :
hadoop fs -rm -r -skipTrash /path_to_file/file_name
To delete a folder from hdfs you can use below given command :
hadoop fs -rm -r -skipTrash /folder_name
You need to use -skipTrash option otherwise error will be prompted.
With Scala:
val fs:FileSystem = FileSystem.get(new URI(filePath), sc.hadoopConfiguration);fs.delete(new Path(filePath), true) // true for recursive
sc is the SparkContext