HDFS的Shell操作

1、基本语法

hadoop fs 具体命令
或者
hdfs dfs 具体命令

(dfs是fs的实现类)

2、常用命令实操

2.1、-help:输出这个命令参数

 hadoop fs -help rm

 2.2、-ls:显示目录信息

hadoop fs -ls /

2.3、-ls -R:递归查看 

hadoop fs -ls -R  /home

2.4、 -mkdir:在HDFS上创建目录

hadoop fs -mkdir -p /test/cs

2.5、-moveFromLocal:从本地剪切粘贴到HDFS

touch test.txt
hadoop fs -moveFromLocal ./test.txt /test/cs

2.6、-appendToFile:追加一个文件到已经存在的文件末尾

touch test1.txt
vim test1.txt
输入
san gu mao lu

hadoop fs -appendToFile test1.txt /test/cs/test.txt

2.7、-cat:显示文件内容

hadoop fs -cat /test/cs/test.txt

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

hadoop fs -chmod 666 /test/cs/test.txt
hadoop fs -chown yzh:yzh /test/cs/test.txt

2.9、-copyFromLocal:从本地文件系统中拷贝文件到HDFS路径去

hadoop fs -copyFromLocal test1.txt /

2.10、-copyToLocal:从HDFS拷贝到本地

hadoop fs -copyToLocal /test/cs/text.txt  ./

2.11、-cp:从HDFS的一个路径复制到另一个路径

hadoop fs -cp /test/ce/test.txt  /

2.12、-mv:在HDFS目录中移动文件

hadoop fs -mv /test/cs/test.txt /

2.13、-get:等同于copyToLocal

hadoop fs -get /test/cs/test.txt  ./

2.14、-getmerge:合并下载多个文件,比如HDFS的目录/test/user/*下有多个文件:log.1,log.2...

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

2.15、-put:等同于copyFromLocal

hadoop fs -put ./test.txt /test/cs

2.16、-tail:显示一个文件的末尾

hadoop fs -tail /test/cs/test.txt

2.17、-rm:删除文件或文件夹

hadoop fs -rm /test/cs/test.txt

2.18、-rmdir:删除空目录

hadoop fs -rmdir /test

2.19、-du:统计文件夹的大小信息

hadoop fs -du -s -h  /test

2.20、-setrep:设置HDFS中文件的副本数量

hadoop fs -setrep 10 /test/cs/test.txt

 相当于数据的备份

原文地址:https://www.cnblogs.com/cq-yangzhou/p/14361190.html