HDFS的常用Shell操作

(0)启动Hadoop集群

?sbin/start-dfs.sh

sbin/start-yarn.sh

(1)-help:输出这个命令参数

?hadoop fs -help rm

(2)-ls: 显示目录信息

?hadoop fs -ls /

(3)-mkdir:在HDFS上创建目录

?hadoop fs -mkdir -p /sanguo/shuguo

(4)-moveFromLocal:从本地剪切粘贴到HDFS

?touch kongming.txt

?hadoop fs ?-moveFromLocal ?./kongming.txt ?/sanguo/shuguo

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

?touch liubei.txt

?vi liubei.txt

输入

san gu mao lu

hadoop fs -appendToFile liubei.txt /sanguo/shuguo/kongming.txt

(6)-cat:显示文件内容

hadoop fs -cat /sanguo/shuguo/kongming.txt

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

hadoop fs ?-chmod ?666 ?/sanguo/shuguo/kongming.txt

hadoop fs ?-chown ?angel:angel? ?/sanguo/shuguo/kongming.txt

(8)-copyFromLocal:从本地文件系统中拷贝文件到HDFS路径去

hadoop fs -copyFromLocal README.txt /

(9)-copyToLocal:从HDFS拷贝到本地

hadoop fs -copyToLocal /sanguo/shuguo/kongming.txt ./

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

hadoop fs -cp /sanguo/shuguo/kongming.txt /zhuge.txt

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

hadoop fs -mv /zhuge.txt /sanguo/shuguo/

(12)-get:等同于copyToLocal,就是从HDFS下载文件到本地

hadoop fs -get /sanguo/shuguo/kongming.txt ./

(13)-getmerge:合并下载多个文件,比如HDFS的目录 /user/atguigu/test下有多个文件:log.1, log.2,log.3,...

hadoop fs -getmerge /user/angel/test/* ./zaiyiqi.txt

(14)-put:等同于copyFromLocal

hadoop fs -put ./zaiyiqi.txt /user/angel/test/

(15)-tail:显示一个文件的末尾

hadoop fs -tail /sanguo/shuguo/kongming.txt

(16)-rm:删除文件或文件夹

hadoop fs -rm /user/angel/test/jinlian2.txt

(17)-rmdir:删除空目录

hadoop fs -mkdir /test

hadoop fs -rmdir /test

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

hadoop fs -du -s -h /user/angel/test

hadoop fs -du ?-h /user/angel/test

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

hadoop fs -setrep 10 /sanguo/shuguo/kongming.txt

?

?

上一篇:HBase的shell操作


下一篇:Linux查看物理CPU个数、核数、逻辑CPU个数