hadoop常見shell命令
阿新 • • 發佈:2020-11-03
-
常見命令:
# 將本地/myfield/a.txt檔案上傳到linux01的hdfs中。 hdfs dfg -put /myfield/a.txt hdfs://linux01:9000/
hadoop常用操作命令
注意:需先配置環境變數
-
列出根目錄下所有目錄或檔案
hdfs dfs -ls /
-
列出/myfield目錄下的所有目錄和檔案
hdfs dfs -ls /myfield
-
列出/myfield目錄下的所有目錄下的所有子檔案
hdfs dfs -ls -R /myfield
-
建立/test目錄
hdfs dfs -mkdir /test
-
建立多級目錄
hdfs dfs -mkdir -p /test/apps/demo1
-
將本地檔案/mnt/1.txt上傳到 /test目錄下
hdfs dfs -put /mnt/1.txt /test
-
下載1.txt檔案到本地
hdfs dfs -get /test/1.txt
-
將 /test/1.txt檔案拷貝到本地
hdfs dfs -copyToLocal /test/1.txt
-
將word.txt檔案拷貝到/test/apps目錄下
hdfs dfs -copyFromLocal word.txt /test/apps
-
將word.txt檔案從本地移動到 /myfield 目錄下
hdfs dfs -moveFromLocal word.txt /myfield
-
將/myfield/word.txt 拷貝一份為 /myfield/word.txt.bak
hdfs dfs -cp /myfield/word.txt /myfield/word.txt.bak
-
將目錄下的子目錄或檔案都拷貝到/logs目錄(如果此目錄不存在會建立)下
hdfs dfs -cp /test/ /logs
-
將/1.txt檔案重新命名為/2.txt
hdfs dfs -mv /1.txt /2.txt
-
將/words.txt檔案移動到/myfield/目錄下
hdfs dfs -mv /2.txt /myfield/
-
將/logs目錄以及子目錄和檔案都刪除
hdfs dfs -rm -r /logs
-
刪除以 “xbs-”開頭的目錄及其子目錄
hdfs dfs -rm -r /xbs-*
-
將/test/1.txt檔案刪除
hdfs dfs -rm /test/1.txt
-
將/test/目錄下面的所有檔案都刪除 (是檔案不是資料夾)
hdfs dfs -rm /test/*
-
檢視HDFS叢集的磁碟空間使用情況
hdfs dfs -df -h
-
獲取/test_hdp.txt檔案內容
hdfs dfs -cat /test_hdp.txt
-
將/field_test/f1.txt 檔案中內容新增到 test_hdp.txt檔案中
hdfs dfs -appendToFile /field_test/f1.txt /test_hdp.txt
-
動態檢視/field_test/f1.txt檔案的內容
hdfs dfs -tail -f /field_test/f1.txt
-
統計/myfield目錄總大小
hdfs dfs -du -s -h /myfield 或 hdfs dfs -du -h /myfield
-
分別統計/test目錄下各個子目錄(或檔案)大小
hdfs dfs -du -s -h /test/*
-
檢視hdfs叢集狀態
hdfs dfsadmin -report
-
清空回收站
hdfs dfs -expunge
-
進入安全模式
hdfs dfsadmin -safemode enter
-
離開安全模式
hdfs dfsadmin -safemode leave