HDFS删除文件

╰半橙微兮° 2022-11-07 04:05 246阅读 0赞

一.删除HDFS上的文件

需求:删除HDFS上的一个文件

代码:

  1. -- 查看文件
  2. hadoop fs -ls /user/hive/warehouse
  3. -- 删除文件
  4. hadoop fs -rm /user/hive/warehouse/test.txt

测试记录:

  1. [root@hp1 hue-httpd]# hadoop fs -ls /user/hive/warehouse
  2. Found 2 items
  3. drwxrwxrwt - root hive 0 2020-11-25 19:15 /user/hive/warehouse/test.db
  4. -rw-rw-rw- 3 root hive 16 2020-11-25 14:53 /user/hive/warehouse/test.txt
  5. [root@hp1 hue-httpd]#
  6. [root@hp1 hue-httpd]# hadoop fs -rm /user/hive/warehouse/test.txt
  7. 20/11/26 10:35:24 INFO fs.TrashPolicyDefault: Moved: 'hdfs://nameservice1/user/hive/warehouse/test.txt' to trash at: hdfs://nameservice1/user/root/.Trash/Current/user/hive/warehouse/test.txt
  8. [root@hp1 hue-httpd]#
  9. [root@hp1 hue-httpd]# hadoop fs -ls /user/root/.Trash/Current/user/hive/warehouse/
  10. Found 1 items
  11. -rw-rw-rw- 3 root hive 16 2020-11-25 14:53 /user/root/.Trash/Current/user/hive/warehouse/test.txt

从上面测试的记录可以看到, 从hdfs上删除的文件,并没有直接被删除,而是移动到了回收站。
如果需要跳过回收站,直接删除,可以使用-skipTrash参数

  1. -- 跳过回收站 直接进行删除
  2. hadoop fs -rm -skipTrash /user/hive/warehouse/test.txt

二.HDFS的回收站

生产环境的hive中,经常大批量的加载及运算数据,例如清理一些临时表。但是清理了表之后,发现hdfs的空间并没有相对应的减少。如果需要收缩空间,可以考虑清空回收站。

生产环境谨慎使用,容易出问题

  1. -- 清空hdfs的回收站
  2. hdfs dfs -expunge

测试记录:
因为root权限不够,先通过sudo -u hdfs 切换到hdfs用户下

  1. [root@hp1 hue-httpd]# sudo -u hdfs hdfs dfs -expunge
  2. [root@hp1 hue-httpd]#

参考

1.《Hadoop权威指南》
2.https://blog.csdn.net/abyslll/article/details/88313961

发表评论

表情:
评论列表 (有 0 条评论,246人围观)

还没有评论,来说两句吧...

相关阅读