Saturday, 2 January 2016

Hadoop: rmdir: remove empty directory

“rmdir” command is used to remove a directory.

Usage:
hadoop fs [generic options] -rmdir [--ignore-fail-on-non-empty] <dir> ...


--ignore-fail-on-non-empty: When using wildcards, do not fail if a directory still contains files.
 
Let me try to delete a non-empty folder.

$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
$
$hadoop fs -rmdir /user/cloudera/demo1
rmdir: `/user/cloudera/demo1': Directory is not empty
As you see the above output, Hadoop throws the error 'Directory is not empty'.

Let me try to delete an empty directory.

$hadoop fs -mkdir /user/cloudera/demo4
$
$hadoop fs -ls /user/cloudera
Found 3 items
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:17 /user/cloudera/demo1
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:03 /user/cloudera/demo2
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:53 /user/cloudera/demo4
$
$hadoop fs -rmdir /user/cloudera/demo4
$
$hadoop fs -ls /user/cloudera
Found 2 items
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:17 /user/cloudera/demo1
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 07:03 /user/cloudera/demo2




Previous                                                 Next                                                 Home

No comments:

Post a Comment