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

移動或重命名

[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#/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章