Hadoop常用命令

2021-09-08 14:31:05 字數 3313 閱讀 9490

1、檢視hadoop hdfs支援的所有命令

hdfs dfs

2、檢視指定目錄下內容

hdfs dfs –ls [檔案目錄]

eg:hdfs dfs –ls /user/hive

3、迴圈列出目錄、子目錄及檔案資訊

hdfs dfs –lsr [檔案目錄]

eg:hdfs dfs –lsr /user/hive

4、檢視某個已存在檔案

hdfs dfs –cat [file_path]

eg:hdfs dfs -cat /user/hive/data.txt

5、檢視最後1kb的內容

hdfs dfs –tail [file_path]

eg:hdfs dfs –tail /user/hive/test.txt

6、將本地檔案儲存至hadoop

hdfs dfs –put [本地位址] [hadoop目錄]

eg:hdfs dfs –put /home/tmp/file.txt /user/tmp

7、將hadoop上某個檔案down至本地已有目錄下

hdfs dfs -get [檔案目錄] [本地目錄]

eg:hdfs dfs –get /user/tmp/ok.txt /home/tmp

8、刪除hadoop上指定檔案

hdfs dfs –rm [-r] [-f] [檔案位址]

eg:hdfs dfs –rm /user/tmp/ok.txt

9、刪除hadoop上指定資料夾(包含子目錄等)

hdfs dfs –rm [-r] [-f] [目錄位址]

eg:hdfs dfs –rmr /user/tmp

10、在hadoop指定目錄內建立新目錄

hdfs dfs –mkdir [hadoop目錄]

eg:hdfs dfs –mkdir /user/tmp

11、在hadoop指定目錄下新建乙個空檔案

使用touchz命令:

hdfs dfs –touchz [file_path]

eg:hdfs dfs -touchz /user/new.txt

12、將hadoop上某個檔案重新命名

使用mv命令:

hdfs dfs –mv [file_path] [new_file_path]

eg:hdfs dfs –mv /user/test.txt /user/ok.txt (將test.txt重新命名為ok.txt)

13、將hadoop指定目錄下所有內容儲存為乙個檔案,同時down至本地

hdfs dfs –getmerge [hadoop目錄] [本地目錄]

eg:hdfs dfs –getmerge /user /home/t

14、將正在執行的hadoop作業kill掉

hdfs job –kill [job-id]

15、hdfs dfs –copyfromlocal test.txt /user/sunlightcs/test.txt

從本地檔案系統複製檔案到hdfs檔案系統,等同於put命令

16、hdfs dfs –copytolocal /user/sunlightcs/test.txt test.txt

從hdfs檔案系統複製檔案到本地檔案系統,等同於get命令

17、hdfs dfs –chgrp [-r] /user/sunlightcs

修改hdfs系統中/user/sunlightcs目錄所屬群組,選項-r遞迴執行,跟linux命令一樣

18、hdfs dfs –chown [-r] /user/sunlightcs

修改hdfs系統中/user/sunlightcs目錄擁有者,選項-r遞迴執行

19、hdfs dfs –chmod [-r] mode /user/sunlightcs

修改hdfs系統中/user/sunlightcs目錄許可權,mode可以為相應許可權的3位數或+/-,選項-r遞迴執行

20、hdfs dfs –count [-q] path

檢視path目錄下,子目錄數、檔案數、檔案大小、檔名/目錄名

21、hdfs dfs –cp src [src …] dst

將檔案從src複製到dst,如果指定了多個src,則dst必須為乙個目錄

22、hdfs dfs –du path

顯示該目錄中每個檔案或目錄的大小

23、hdfs dfs –dus path

類似於du,path為目錄時,會顯示該目錄的總大小

24、hdfs dfs –expunge

清空**站,檔案被刪除時,它首先會移到臨時目錄.trash/中,當超過延遲時間之後,檔案才會被永久刪除

25、hdfs dfs –getmerge src [src …] localdst [addnl]

獲取由src指定的所有檔案,將它們合併為單個檔案,並寫入本地檔案系統中的localdst,選項addnl將在每個檔案的末尾處加上乙個換行符

26、hdfs dfs –touchz path

建立長度為0的空檔案

27、hdfs dfs –test –[ezd] path

對path進行如下型別的檢查:

-e path是否存在,如果path存在,返回0,否則返回1

-z 檔案是否為空,如果長度為0,返回0,否則返回1

-d 是否為目錄,如果path為目錄,返回0,否則返回1

28、hdfs dfs –text path

顯示檔案的內容,當檔案為文字檔案時,等同於cat,檔案為壓縮格式(gzip以及hadoop的二進位制序列檔案格式)時,會先解壓縮

29、hdfs dfs –help ls

檢視某個[ls]命令的幫助文件

hadoop 常用命令

啟動hadoop 進入hadoop home目錄。執行sh bin start all.sh 或者是在hadoop 的目錄下能看到他的bin目錄 執行 bin start all.sh 關閉hadoop 進入hadoop home目錄。執行sh bin stop all.sh 同上。1 檢視指定目錄...

hadoop常用命令

1 檢視指定目錄下內容 hadoop dfs ls 檔案目錄 eg hadoop dfs ls user wangkai.pt 2 開啟某個已存在檔案 hadoop dfs cat file path eg hadoop dfs cat user wangkai.pt data.txt 3 將本地檔...

hadoop常用命令

1 檢視指定目錄下內容 hadoop dfs ls 檔案目錄 eg hadoop dfs ls user wangkai.pt 2 開啟某個已存在檔案 hadoop dfs cat file path eg hadoop dfs cat user wangkai.pt data.txt 3 將本地檔...