基本语法 hadoop fs 具体命令 hdfs dfs 具体命令 [root@master ~]# hadoop fs -help rm 先启动集群 sbin/start-dfs.sh [root@master hadoop-3.1.3]# hadoop fs -mkdir /sanguo [root@master hadoop-3.1.3]# vim shuguo.txt
上传
1)-moveFromLocal: 从本地剪切粘贴到HDFS [root@master hadoop-3.1.3]# hadoop fs -moveFromLocal ./shuguo.txt /sanguo 2)-copyFromLocal: 从本地文件系统中拷贝文件到HDFS路径去 [root@master hadoop-3.1.3]# hadoop fs -copyFromLocal ./weiguo.txt /sanguo 3)-put: 等同于copyFromLocal,生产环境更习惯用put [root@master hadoop-3.1.3]# hadoop fs -put ./wuguo.txt /sanguo 4)-appendToFile: 追加一个文件到已经存在的文件末尾 [root@master hadoop-3.1.3]# hadoop fs -appendToFile liubei.txt /sanguo/shuguo.txt
下载
1)copyToLocal: 从HDFS拷贝到本地 [root@master hadoop-3.1.3]# hadoop fs -copyToLocal /sanguo/shuguo.txt ./ 2)get:等同于copyToLocal,生产环境更习惯用get [root@master hadoop-3.1.3]# hadoop fs -get /sanguo/shuguo.txt ./shuguo2.txt
直接操作
1)-ls:显示目录信息 [root@master hadoop-3.1.3]# hadoop fs -ls / [root@master hadoop-3.1.3]# hadoop fs -ls /sanguo 2)-cat:显示文件内容 [root@master hadoop-3.1.3]# hadoop fs -cat /sanguo/shuguo.txt 3)-chgrp、-chmod、-chown:修改文件所属权限 [root@master hadoop-3.1.3]# hadoop fs -chown root:root /sanguo/shuguo.txt 4)-mkdir:创建路径 [root@master hadoop-3.1.3]# hadoop fs -mkdir /jinguo 5)-cp:从HDFS的一个路径拷贝到HDFS的另一个路径 [root@master hadoop-3.1.3]# hadoop fs -cp /sanguo/shuguo.txt /jinguo 6)-mv:在HDFS目录中移动文件 [root@master hadoop-3.1.3]# hadoop fs -mv /sanguo/wuguo.txt /jinguo [root@master hadoop-3.1.3]# hadoop fs -mv /sanguo/weiguo.txt /jinguo 7)-tail:显示一个文件的末尾1kb的数据 [root@master hadoop-3.1.3]# hadoop fs -tail /jinguo/shuguo.txt 8)-rm:删除文件或文件夹 [root@master hadoop-3.1.3]# hadoop fs -rm /sanguo/shuguo.txt 9)-rm -r:递归删除目录及目录里面内容 [root@master hadoop-3.1.3]# hadoop fs -rm -r /sanguo 10)-du:统计文件夹的大小信息 [root@master hadoop-3.1.3]# hadoop fs -du -s -h /jinguo 27 81 /jinguo [root@master hadoop-3.1.3]# hadoop fs -du -h /jinguo 14 42 /jinguo/shuguo.txt 7 21 /jinguo/weiguo.txt 6 18 /jinguo/wuguo.txt 11)-setrep:设置HDFS中文件的副本数量
|