Hadoop系列(三)Hadoop三大核心之HDFS shell常用命令

HDFS常用命令

help 查看所有命令

[172.23.7.9:hadoop]$ hadoop fs help

查看路径文件

[172.23.7.9:hadoop]$ hadoop fs -ls /

创建文件夹

[172.23.7.9:hadoop]$ hadoop fs -mkdir /test

创建多级文件夹

[172.23.7.9:hadoop]$ hadoop fs -mkdir -p /test/test1/test2

查看指定目录下和子目录下所有文件

[172.23.7.9:hadoop]$ hadoop fs -ls -R /test

上传文件

[172.23.7.9:hadoop]$ hadoop fs -put part.txt /test

or

[172.23.7.9:hadoop]$ hadoop fs -copyFromLocal part.txt /test

下载文件

[172.23.7.9:hadoop]$ hadoop fs -get /test/part.txt ~/test

or

[172.23.7.9:hadoop]$ hadoop fs -copyToLocal /test/part.txt ~/test

合并下载

[172.23.7.9:hadoop]$ hadoop fs -getmerge /test/part0.txt /test/part1.txt ./temp.txt

复制

[172.23.7.9:hadoop]$ hadoop fs -cp /test/part.txt /output
MapReduce的方式
[172.23.7.9:hadoop]$ hadoop distcp -skipcrccheck /test/part.txt /output
distcp指定队列
[172.23.7.9:hadoop]$ hadoop distcp -Dmapred.job.queue.name=$queue_name /test/part.txt /output

移动或重命名

[172.23.7.9:hadoop]$ hadoop fs -mv /test/part.txt /output

删除

[172.23.7.9:hadoop]$ hadoop fs -rm /test/part.txt

强制删除

[172.23.7.9:hadoop]$ hadoop fs -rm -r /test/part.txt

查看文件内容

[172.23.7.9:hadoop]$ hadoop fs -cat /test/part.txt

统计文件行数

[172.23.7.9:hadoop]$ hadoop fs -cat /test/part.txt | wc -l

返回文件前n行(以10行为例)

[172.23.7.9:hadoop]$ hadoop fs -cat /test/part.txt | head -10

返回文件后n行(以10行为例)

[172.23.7.9:hadoop]$ hadoop fs -cat /test/part.txt | tail -10

随机返回n行(以10行为例)

[172.23.7.9:hadoop]$ hadoop fs -cat /test/part.txt | shuf -n 10

显示文件大小

[172.23.7.9:hadoop]$ hadoop fs -du -h /test/part.txt

test

[172.23.7.9:hadoop]$ hadoop fs -test -[ezd] /test/part.txt

选项:
-e 检查文件是否存在。如果存在则返回0。
-z 检查文件是否是0字节。如果是则返回0。
-d 如果路径是个目录,则返回1,否则返回0。

web界面

http://xx.xx.xx.xx:9870/explorer.html#/

Hadoop系列(三)Hadoop三大核心之HDFS shell常用命令