HDFS的shell操作
1.创建/sanguo文件包
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -mkdir /sanguo
2.上传
[admin@hadoop1002 hadoop-3.1.3]$ vim weiguo.txt
编辑
weiguo
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -put ./weiguo.txt /sanguo
[admin@hadoop1002 hadoop-3.1.3]$ vim shuguo.txt
编辑如下
shuguo
#-moveFromLocal 剪贴至服务器
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -moveFromLocal ./shuguo.txt /sanguo
#-copyFromLocal 复制至服务器
[admin@hadoop1002 hadoop-3.1.3]$ vim wuguo.txt
编辑
wuguo
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -put ./wuguo.txt /sanguo
#-appendToFile:追加一个文件到已经存在的文件末尾
[admin@hadoop1002 hadoop-3.1.3]$ vim liubei.txt
编辑
liubei
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -appendToFile liubei.txt /sanguo/shuguo.txt
3.下载
#-copyToLocal:从HDFS拷贝到本地
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -copyToLocal /sanguo/shuguo.txt ./
#-get等同于 -copyToLocal
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -get /sanguo/shuguo.txt ./shuguo2.txt
4.HDFS直接操作
#-ls 直接查看文件信息
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -ls /sanguo
#-cat:显示文件内容
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -cat /sanguo/shuguo.txt
#-chgrp、-chmod、-chown:Linux文件系统中的用法
一样,修改文件所属权限
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -chmod 666 /sanguo/shuguo.txt
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -chown admin:admin /sanguo/shuguo.txt
#-mkdir:创建目录
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -mkdir /jinguo
#-cp 在HDFS中拷贝
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -cp /sanguo/shuguo.txt /jinguo
#-mv 在HDFS中移动文件
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -mv /sanguo/wuguo.txt /jinguo
#-tail 显示文件追踪默未1kb内容
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -tail /sanguo/shuguo.txt
#-rm 删除文件或目录
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -rm /sanguo/shuguo.txt
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -rm -r /sanguo
#-du 查看文件大小
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -du -h /jinguo
14 42 /jinguo/shuguo.txt
7 21 /jinguo/weiguo
6 18 /jinguo/wuguo.txt
说明:7表示文件大小;21表示7*3个副本;/jinguo表示
查看的目录
#setrep 设置副本数量
[admin@hadoop1002 hadoop-3.1.3]$ hadoop fs -setrep 10 /jinguo/shuguo.txt
以上就是Hadoop的HDFS的shell操作。请参考并多多指正!