栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

HDFS常用命令

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

HDFS常用命令

1.上传 

1).创建文件夹

hadoop fs -mkdir /testdir

2).-moveFromLocal:从本地剪切到hdfs,会删除本地文件

hadoop fs -moveFromLocal ./hello.txt /testdir

3).-copyFromLocal:从本地文件系统中拷贝文件到HDFS路径去,-put:等同于copyFromLocal,

hadoop fs -copyFromLocal ./test.txt /testdir
hadoop fs -put ./test.txt /testdir

4).-appendToFile:追加一个文件到已经存在的文件末尾

hadoop fs -appendToFile ./append.txt /testdir/hello.txt

查看追加的内容 

2.下载

1)get:等同于copyToLocal,生产环境更习惯用get

hadoop fs -put ./test.txt /testdir
3.操作HDFS

1)-ls 

hadoop fs -ls /testdir
Found 2 items
-rw-r--r--   3 zjx supergroup         21 2022-07-09 09:43 /testdir/hello.txt
-rw-r--r--   3 zjx supergroup         21 2022-07-09 09:42 /testdir/test.txt

2)-cat 显示文件内容

hadoop fs -cat /testdir/hello.txt

3)-chgrp、-chmod、-chown:Linux文件系统中的用法一样,修改文件所属权限

4)-mkdir

5)-cp :从HDFS的一个路径拷贝到HDFS的另一个路径

6)-mv:在HDFS目录中移动文件

7)-tail:显示一个文件的末尾1kb的数据

hadoop fs -tail /testdir/hello.txt
2022-07-09 10:00:07,423 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false
hh
cc
dd
append file

8)-rm:删除文件或文件夹

9)-rm -r:递归删除目录及目录里面内容

10)-du统计文件夹的大小信息

hadoop fs -du -s -h /testdir
78  234  /testdir

hadoop fs -du -h /testdir
21  63   /testdir/hello.txt
57  171  /testdir/test.txt

说明:27表示文件大小;81表示27*3个副本;/jinguo表示查看的目录

11)-setrep:设置HDFS中文件的副本数量

hadoop fs -setrep 5 /testdir/test.txt

这里设置的副本数只是记录在NameNode的元数据中,是否真的会有这么多副本,还得看DataNode的数量。因为目前只有3台设备,最多也就3个副本,只有节点数的增加到10台时,副本数才能达到10。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1009061.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号