HDFS常用命令


HDFS:它是一個文件系統,用於存儲文件。它是分布式的。由多台服務器聯合實現功能。適合一次寫入,多次讀出的場景,不支持文件修改,適合做數據分析,不適合做網盤應用。

 

HDFS架構圖

 

 

 常用命令

0)啟動 Hadoop 集群(方便后續的測試)

  [atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh

 [atguigu@hadoop103 hadoop-2.7.2]$ sbin/start-yarn.sh

1-help:輸出這個命令參數

  [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -help rm

 2-ls: 顯示目錄信息

 [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -ls /

3-mkdir:在 hdfs 上創建目錄

 [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mkdir -p /user/atguigu/test

4-moveFromLocal 從本地剪切粘貼到 hdfs

 [atguigu@hadoop102 hadoop-2.7.2]$ touch jinlian.txt

 [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs  -moveFromLocal  ./jinlian.txt  

/user/atguigu/test

5--appendToFile  :追加一個文件到已經存在的文件末尾

[atguigu@hadoop102 hadoop-2.7.2]$ touch ximen.txt

[atguigu@hadoop102 hadoop-2.7.2]$ vi ximen.txt

輸入

wo ai  jinlian

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -appendToFile ximen.txt

/user/atguigu/test/jinlian.txt

6-cat :顯示文件內容

7-tail:顯示一個文件的末尾

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -tail /user/atguigu/test/jinlian.txt

8-chgrp -chmod-chownlinux 文件系統中的用法一樣,修改文件所屬權限

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs  -chmod  666  

/user/atguigu/test/jinlian.txt

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs  -chown  atguigu:atguigu   

/user/atguigu/test/jinlian.txt

9-copyFromLocal:從本地文件系統中拷貝文件到 hdfs 路徑去

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -copyFromLocal README.txt

/user/atguigu/test

10-copyToLocal:從 hdfs 拷貝到本地

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -copyToLocal

/user/atguigu/test/jinlian.txt ./jinlian.txt

11-cp :從 hdfs 的一個路徑拷貝到 hdfs 的另一個路徑

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -cp /user/atguigu/test/jinlian.txt

/jinlian2.txt

12-mv:在 hdfs 目錄中移動文件

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mv /jinlian2.txt /user/atguigu/test/

13-get:等同於 copyToLocal,就是從 hdfs 下載文件到本地

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -get /user/atguigu/test/jinlian2.txt ./ 14-getmerge  :合並下載多個文件,比如 hdfs 的目錄 /aaa/下有多個文件:log.1, log.2,log.3,... [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -getmerge /user/atguigu/test/* ./zaiyiqi.txt 15-put:等同於 copyFromLocal

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -put ./zaiyiqi.txt /user/atguigu/test/

16-rm:刪除文件或文件夾

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rm /user/atguigu/test/jinlian2.txt

17-rmdir:刪除空目錄

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mkdir /test

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rmdir /test

18-df :統計文件系統的可用空間信息

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -df -h /

19-du 統計文件夾的大小信息

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -du -s -h /user/atguigu/test

2.7 K  /user/atguigu/test

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -du  -h /user/atguigu/test

1.3 K  /user/atguigu/test/README.txt

15     /user/atguigu/test/jinlian.txt

1.4 K  /user/atguigu/test/zaiyiqi.txt 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM