Saturday 2 January 2016

Hadoop: rm: Remove a file from the directory

“rm” command is used to remove files.

Usage:
hadoop fs [generic options] -rm [-f] [-r|-R] [-skipTrash] <src> ...
 
Simple Syntax
hadoop fs -rm {file_path_in_hdfs}

Let us see it with an example.

$hadoop fs -ls /user/cloudera/demo1
Found 6 items
-rw-r--r--   1 cloudera cloudera          2 2022-03-22 23:58 /user/cloudera/demo1/a.txt
-rw-r--r--   1 cloudera cloudera    4724690 2022-03-22 23:57 /user/cloudera/demo1/apacheNifi.docx
-rw-r--r--   1 cloudera cloudera    6166736 2022-03-22 23:57 /user/cloudera/demo1/atlas.docx
-rw-r--r--   1 cloudera cloudera    9147128 2022-03-22 23:57 /user/cloudera/demo1/atlasClient.docx
-rw-r--r--   1 cloudera cloudera    6988969 2022-03-22 23:58 /user/cloudera/demo1/gradle.docx
-rw-r--r--   1 cloudera cloudera    8986359 2022-03-22 23:58 /user/cloudera/demo1/maven.docx

 Let us delete the file '/user/cloudera/demo1/apacheNifi.docx' and confirm the same by printing.

 

$hadoop fs -rm /user/cloudera/demo1/apacheNifi.docx
Deleted /user/cloudera/demo1/apacheNifi.docx
$
$hadoop fs -ls /user/cloudera/demo1
Found 5 items
-rw-r--r--   1 cloudera cloudera          2 2022-03-22 23:58 /user/cloudera/demo1/a.txt
-rw-r--r--   1 cloudera cloudera    6166736 2022-03-22 23:57 /user/cloudera/demo1/atlas.docx
-rw-r--r--   1 cloudera cloudera    9147128 2022-03-22 23:57 /user/cloudera/demo1/atlasClient.docx
-rw-r--r--   1 cloudera cloudera    6988969 2022-03-22 23:58 /user/cloudera/demo1/gradle.docx
-rw-r--r--   1 cloudera cloudera    8986359 2022-03-22 23:58 /user/cloudera/demo1/maven.docx
$

 


 

 

 


Previous                                                 Next                                                 Home

No comments:

Post a Comment