Which Hadoop FS Command Deletes Files from HDFS Safely?
Master the hadoop fs -rm command to delete files or directories from HDFS, including recursive options and trash handling, essential for Hadoop cluster management and storage cleanup.
Question
Which Hadoop command would you use to delete a file from HDFS?
A. hadoop fs -put
B. hadoop fs -rm
C. hadoop fs -ls
D. hdfs namenode -format
Answer
B. hadoop fs -rm
Explanation
The hadoop fs -rm command deletes specified files or directories from HDFS, moving them to the trash (if enabled) or permanently removing them with options like -skipTrash. It works on individual files or non-empty directories when combined with -r for recursive deletion, providing a safe and standard way to manage HDFS storage by removing unwanted data. Other options like -put (upload), -ls (list), and namenode -format (cluster reinitialization) serve unrelated purposes and cannot delete files.