HDFS 常用shell指令操作
-
-
-
- -help:幫助
- -ls: 顯示目錄資訊
- -mkdir:在hdfs上建立目錄
- -moveFromLocal :從本地剪切粘貼到hdfs
- -moveToLocal:從hdfs剪切粘貼到本地(尚未實作)
- –appendToFile :追加一個檔案到已經存在的檔案末尾
- -cat :顯示檔案内容
- -tail:顯示一個檔案的末尾
- -chgrp 、-chmod、-chown:修改檔案所屬權限
- -copyFromLocal:從本地檔案系統中拷貝檔案到hdfs路徑去
- -copyToLocal:從hdfs拷貝到本地
- -cp :從hdfs的一個路徑拷貝到hdfs的另一個路徑
- -mv:在hdfs目錄中移動檔案
- -get:等同于copyToLocal,就是從hdfs下載下傳檔案到本地
- -getmerge :合并下載下傳多個檔案
- -put:等同于copyFromLocal
- -rm:删除檔案或檔案夾
- -rmdir:删除空目錄
- -df :統計檔案系統的可用空間資訊
- -du:統計檔案夾的大小資訊
- -count:統計一個指定目錄下的檔案節點數量
- -setrep:設定hdfs中檔案的副本數量
- hdfs fsck / :檢視叢集的狀态
-help:幫助
-help + 指令:輸出這個指令參數
eg:
[[email protected] ~]$ hdfs dfs -help rm
-rm [-f] [-r|-R] [-skipTrash] <src> ... :
Delete all files that match the specified file pattern. Equivalent to the Unix
command "rm <src>"
-skipTrash option bypasses trash, if enabled, and immediately deletes <src>
-f If the file does not exist, do not display a diagnostic message or
modify the exit status to reflect an error.
-[rR] Recursively deletes directories
-ls: 顯示目錄資訊
hadoop fs -ls /
eg:
[[email protected] ~]$ hadoop fs -ls /
Found 4 items
drwxr-xr-x - jacob supergroup 0 2019-12-03 19:32 /input
drwxr-xr-x - jacob supergroup 0 2019-12-04 01:22 /output
drwx-wx-wx - jacob supergroup 0 2019-10-04 18:37 /tmp
drwxr-xr-x - jacob supergroup 0 2019-10-18 04:05 /user
-mkdir:在hdfs上建立目錄
hadoop fs -mkdir -p /aaa/bbb/cc/dd
-p代表級聯
-moveFromLocal :從本地剪切粘貼到hdfs
hadoop fs - moveFromLocal /home/hadoop/a.txt /aaa/bbb/cc/dd
-moveToLocal:從hdfs剪切粘貼到本地(尚未實作)
hadoop fs -help moveToLocal
–appendToFile :追加一個檔案到已經存在的檔案末尾
hadoop fs -appendToFile ./hello.txt /hello.txt
-cat :顯示檔案内容
hdfs dfs -cat /b.txt
-tail:顯示一個檔案的末尾
hadoop fs -tail /weblog/access_log.1
-chgrp 、-chmod、-chown:修改檔案所屬權限
和linux檔案系統中的用法一樣
hadoop fs -chown someuser:somegrp /hello.txt
-copyFromLocal:從本地檔案系統中拷貝檔案到hdfs路徑去
hadoop fs -copyFromLocal ./jdk.tar.gz /aaa/
-copyToLocal:從hdfs拷貝到本地
hadoop fs -copyToLocal /user/hello.txt ./hello.txt
-cp :從hdfs的一個路徑拷貝到hdfs的另一個路徑
hadoop fs -cp /aaa/jdk.tar.gz /bbb/jdk.tar.gz.2
-mv:在hdfs目錄中移動檔案
hadoop fs -mv /aaa/jdk.tar.gz /
-get:等同于copyToLocal,就是從hdfs下載下傳檔案到本地
hadoop fs -get /user/hello.txt ./
-getmerge :合并下載下傳多個檔案
比如hdfs的目錄 /aaa/下有多個檔案:log.1, log.2,log.3,… 可以一次性下載下傳并合并
hadoop fs -getmerge /aaa/log.* ./log.sum
-put:等同于copyFromLocal
hadoop fs -put /aaa/jdk.tar.gz /bbb/jdk.tar.gz.2
-rm:删除檔案或檔案夾
hadoop fs -rm -r /aaa/bbb/
-rmdir:删除空目錄
hadoop fs -rmdir /aaa/bbb/ccc
-df :統計檔案系統的可用空間資訊
hadoop fs -df -h /
eg:
[[email protected] ~]$ hadoop fs -df -h /
Filesystem Size Used Available Use%
hdfs://bd1904 51.3 G 316.4 M 31.1 G 1%
-du:統計檔案夾的大小資訊
hadoop fs -du -s -h /input
-count:統計一個指定目錄下的檔案節點數量
hadoop fs -count /input
-setrep:設定hdfs中檔案的副本數量
hadoop fs -setrep 3 /aaa/jdk.tar.gz
這裡設定的副本數隻是記錄在namenode的中繼資料中,是否真的會有這麼多副本,還得看datanode的數量。因為目前隻有3台裝置,最多也就3個副本,隻有節點數的增加到10台時,副本數才能達到10。
hdfs fsck / :檢視叢集的狀态
hdfs fsck / : 檢視叢集的狀态(運作狀态)
[[email protected] ~]$ hdfs fsck /
Connecting to namenode via http://hadoop02:50070/fsck?ugi=jacob&path=%2F
FSCK started by jacob (auth:SIMPLE) from /192.168.5.109 for path / at Wed Dec 25 18:31:23 CST 2019
....................................................................................................
....................................................................................................
.............................................................................Status: HEALTHY
Total size: 159395771 B
Total dirs: 262
Total files: 877
Total symlinks: 0
Total blocks (validated): 870 (avg. block size 183213 B)
Minimally replicated blocks: 870 (100.0 %)
Over-replicated blocks: 0 (0.0 %)
Under-replicated blocks: 0 (0.0 %)
Mis-replicated blocks: 0 (0.0 %)
Default replication factor: 2
Average block replication: 2.0
Corrupt blocks: 0
Missing replicas: 0 (0.0 %)
Number of data-nodes: 3
Number of racks: 1
FSCK ended at Wed Dec 25 18:31:23 CST 2019 in 254 milliseconds