HDFS命令行客户端使用,命令行客户端支持的命令参数,常用命令参数介绍
3.HDFS的shell(命令行客戶端)操作
3.1 HDFS命令行客戶端使用
HDFS提供shell命令行客戶端,使用方法如下:
[toto@hadoop hadoop-2.8.0]$ hdfs dfs -ls /???? (推薦使用這種方式,hdfs現在這種是最新的一種方式) Found 4 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 03:23 /hive drwx------?? - toto supergroup????????? 0 2017-05-29 14:47 /tmp drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:47 /user [toto@hadoop hadoop-2.8.0]$ ? 或者使用: [toto@hadoop hadoop-2.8.0]$ hadoop fs -ls / Found 4 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 03:23 /hive drwx------?? - toto supergroup????????? 0 2017-05-29 14:47 /tmp drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:47 /user [toto@hadoop hadoop-2.8.0]$ |
?
3.2 命令行客戶端支持的命令參數
[toto@hadoop learn]$ hadoop fs help Usage: hadoop fs [generic options] ?????? [-appendToFile <localsrc> ... <dst>] ?????? [-cat [-ignoreCrc] <src> ...] ?????? [-checksum <src> ...] ?????? [-chgrp [-R] GROUP PATH...] ?????? [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...] ?????? [-chown [-R] [OWNER][:[GROUP]] PATH...] ?????? [-copyFromLocal [-f] [-p] [-l] [-d] <localsrc> ... <dst>] ?????? [-copyToLocal [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] ?????? [-count [-q] [-h] [-v] [-t [<storage type>]] [-u] [-x] <path> ...] ?????? [-cp [-f] [-p | -p[topax]] [-d] <src> ... <dst>] ?????? [-createSnapshot <snapshotDir> [<snapshotName>]] ?????? [-deleteSnapshot <snapshotDir> <snapshotName>] ?????? [-df [-h] [<path> ...]] ?????? [-du [-s] [-h] [-x] <path> ...] ?????? [-expunge] ?????? [-find <path> ... <expression> ...] ?????? [-get [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] ?????? [-getfacl [-R] <path>] ?????? [-getfattr [-R] {-n name | -d} [-e en] <path>] ?????? [-getmerge [-nl] [-skip-empty-file] <src> <localdst>] ?????? [-help [cmd ...]] ?????? [-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...]] ?????? [-mkdir [-p] <path> ...] ?????? [-moveFromLocal <localsrc> ... <dst>] ?????? [-moveToLocal <src> <localdst>] ?????? [-mv <src> ... <dst>] ?????? [-put [-f] [-p] [-l] [-d] <localsrc> ... <dst>] ?????? [-renameSnapshot <snapshotDir> <oldName> <newName>] ?????? [-rm [-f] [-r|-R] [-skipTrash] [-safely] <src> ...] ?????? [-rmdir [--ignore-fail-on-non-empty] <dir> ...] ?????? [-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]] ?????? [-setfattr {-n name [-v value] | -x name} <path>] ?????? [-setrep [-R] [-w] <rep> <path> ...] ?????? [-stat [format] <path> ...] ?????? [-tail [-f] <file>] ?????? [-test -[defsz] <path>] ?????? [-text [-ignoreCrc] <src> ...] ?????? [-touchz <path> ...] ?????? [-truncate [-w] <length> <path> ...] ?????? [-usage [cmd ...]] ? ?[toto@hadoop learn]$ |
?
3.2 常用命令參數介紹
關于hdfs的命令,可以查看http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html
FS Shell
調用文件系統(FS)Shell命令應使用?bin/hadoop fs <args>的形式。 所有的的FS shell命令使用URI路徑作為參數。URI格式是scheme://authority/path。對HDFS文件系統,scheme是hdfs,對本地文件系統,scheme是file。其中scheme和authority參數都是可選的,如果未加指定,就會使用配置中指定的默認scheme。一個HDFS文件或目錄比如/parent/child可以表示成hdfs://namenode:namenodeport/parent/child,或者更簡單的/parent/child(假設你配置文件中的默認值是namenode:namenodeport)。大多數FS Shell命令的行為和對應的Unix Shell命令類似,不同之處會在下面介紹各命令使用詳情時指出。出錯信息會輸出到stderr,其他信息輸出到stdout。
?
?
-help???????????? 功能:輸出這個命令參數手冊 |
-ls? 功能:顯示目錄信息 示例: hadoop fs -ls hdfs://hadoop:9000/ 備注:這些參數中,所有的hdfs路徑都可以簡寫 -->hadoop fs -ls /?? 等同于上一條命令的效果 [toto@hadoop learn]$ hadoop fs -ls hdfs://hadoop:9000/ Found 4 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:01 hdfs://hadoop:9000/findbugs-1.3.9 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 03:23 hdfs://hadoop:9000/hive drwx------?? - toto supergroup????????? 0 2017-05-29 14:47 hdfs://hadoop:9000/tmp drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:47 hdfs://hadoop:9000/user [toto@hadoop learn]$ ? 上面的命令等同:hadoop fs -ls / ? [toto@hadoop learn]$ hadoop fs -ls hdfs://hadoop:9000/findbugs-1.3.9 下面的命令表示同時列出hdfs://hadoop:9000/findbugs-1.3.9和hive下面的內容 [toto@hadoop learn]$ hadoop fs -ls hdfs://hadoop:9000/findbugs-1.3.9 /hive |
-mkdir??? ? mkdir使用方法:hadoop fs -mkdir <paths>? 功能:在hdfs上創建目錄,接受路徑指定的uri作為參數,創建這些目錄。其行為類似于Unix的mkdir -p,它會創建路徑中的各級父目錄。 示例:hadoop fs? -mkdir? -p? /aaa/bbb/cc/dd ? 再如示例: [toto@hadoop learn]$hadoop fs –mkdir -p /user/hadoop/dir1 /user/hadoop/dir2 [toto@hadoop learn]$ hadoop fs -mkdir -p hdfs://hadoop:9000/toto hdfs://hadoop:9000/toto2 [toto@hadoop learn]$ hadoop fs -ls / Found 6 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 03:23 /hive drwx------? ?- toto supergroup????????? 0 2017-05-29 14:47 /tmp drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:40 /toto drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:41 /toto2 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:36 /user ? 對應瀏覽器上的訪問效果如下:http://hadoop:50070/explorer.html#/
顯示效果一致 |
-moveFromLocal?? 使用方法:dfs -moveFromLocal <src> <dst> 功能:從本地剪切粘貼到hdfs [toto@hadoop learn]$ ls hadoop? LICENSE-ASM.txt [toto@hadoop learn]$ hdfs dfs -moveFromLocal LICENSE-ASM.txt /toto [toto@hadoop learn]$ hdfs dfs -ls /toto Found 1 items -rw-r--r--?? 3 toto supergroup?????? 1511 2017-05-29 23:50 /toto/LICENSE-ASM.txt [toto@hadoop learn]$ ? 再如: [toto@hadoop learn]$ hadoop fs -moveFromLocal hadoop /toto [toto@hadoop learn]$ hadoop fs -ls /toto Found 2 items -rw-r--r--?? 3 toto supergroup?????? 1511 2017-05-29 23:50 /toto/LICENSE-ASM.txt drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:53 /toto/hadoop [toto@hadoop learn]$ ? -moveToLocal????????????? 功能:從hdfs剪切粘貼到本地 示例:hadoop? fs? - moveToLocal?? /aaa/bbb/cc/dd? /home/hadoop/a.txt |
--appendToFile? 功能:追加一個文件到已經存在的文件末尾 示例:hadoop? fs? -appendToFile? ./hello.txt? hdfs://hadoop:9000/hello.txt 可以簡寫為: Hadoop? fs? -appendToFile? ./hello.txt? /hello.txt ? 實際案例: [toto@hadoop learn]$ hadoop fs -put text.txt /toto [toto@hadoop learn]$ hadoop fs -ls /toto Found 3 items -rw-r--r--?? 3 toto supergroup?????? 1511 2017-05-29 23:50 /toto/LICENSE-ASM.txt drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:53 /toto/hadoop -rw-r--r--?? 3 toto supergroup????????? 0 2017-05-29 23:59 /toto/text.txt [toto@hadoop learn]$ cat hello.txt 示例:hadoop? fs? -appendToFile? ./hello.txt? hdfs://hadoop:9000/hello.txt 可以簡寫為: Hadoop? fs? -appendToFile? ./hello.txt? /hello.txt ? 將文件上傳到hdfs [toto@hadoop learn]$ hadoop fs -appendToFile ./hello.txt hdfs://hadoop:9000/toto/text.txt 查看拼接到text.txt中的內容 [toto@hadoop learn]$ hadoop fs -cat /toto/text.txt 示例:hadoop? fs? -appendToFile? ./hello.txt? hdfs://hadoop:9000/hello.txt 可以簡寫為: Hadoop? fs? -appendToFile? ./hello.txt? /hello.txt ? [toto@hadoop learn]$ |
-cat? 功能:顯示文件內容? 示例:hadoop fs -cat? /hello.txt ? ? -tail???????????????? 功能:顯示一個文件的末尾 示例:hadoop? fs? -tail? /weblog/access_log.1 實際案例: [toto@hadoop learn]$ hadoop fs -tail /toto/text.txt 示例:hadoop? fs? -appendToFile? ./hello.txt? hdfs://hadoop:9000/hello.txt 可以簡寫為: Hadoop? fs? -appendToFile? ./hello.txt? /hello.txt ? [toto@hadoop learn]$ ? ? ? -text????????????????? 功能:以字符形式打印一個文件的內容 示例:hadoop? fs? -text? /weblog/access_log.1 實際案例: [toto@hadoop learn]$ hadoop fs -text /toto/text.txt 示例:hadoop? fs? -appendToFile? ./hello.txt? hdfs://hadoop:9000/hello.txt 可以簡寫為: Hadoop? fs? -appendToFile? ./hello.txt? /hello.txt ? [toto@hadoop learn]$ |
-chgrp -chmod -chown 功能:linux文件系統中的用法一樣,對文件所屬權限 示例: hadoop? fs? -chmod? 666? /hello.txt hadoop? fs? -chown? someuser:somegrp?? /hello.txt ? 實際案例: [toto@hadoop learn]$ hadoop fs -chmod 777 /toto/text.txt [toto@hadoop learn]$ hadoop fs -ls /toto/text.txt -rwxrwxrwx?? 3 toto supergroup??????? 149 2017-05-30 00:01 /toto/text.txt [toto@hadoop learn]$ hadoop fs -chmod 666 /toto/text.txt [toto@hadoop learn]$ hadoop fs -ls /toto/text.txt -rw-rw-rw-?? 3 toto supergroup??????? 149 2017-05-30 00:01 /toto/text.txt [toto@hadoop learn]$ |
-copyFromLocal??? 功能:從本地文件系統中拷貝文件到hdfs路徑去 示例:hadoop? fs? -copyFromLocal? ./jdk.tar.gz? /aaa/ ? 實際案例: [toto@hadoop learn]$ cat hello.txt 示例:hadoop? fs? -appendToFile? ./hello.txt? hdfs://hadoop:9000/hello.txt 可以簡寫為: Hadoop? fs? -appendToFile? ./hello.txt? /hello.txt ? [toto@hadoop learn]$ hadoop fs -copyFromLocal ./hello.txt /toto2 [toto@hadoop learn]$ ls hello.txt? text.txt [toto@hadoop learn]$ hadoop fs -ls /toto2 Found 1 items -rw-r--r--?? 3 toto supergroup??????? 149 2017-05-30 00:09 /toto2/hello.txt [toto@hadoop learn]$ ? -copyToLocal????? 功能:從hdfs拷貝到本地 示例:hadoop fs -copyToLocal /aaa/jdk.tar.gz 實際案例: [toto@hadoop learn]$ hadoop fs -ls / Found 6 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 03:23 /hive drwx------?? - toto supergroup????????? 0 2017-05-29 14:47 /tmp drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:59 /toto drwxr-xr-x?? - toto supergroup????????? 0 2017-05-30 00:09 /toto2 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:36 /user [toto@hadoop learn]$ hadoop fs -copyToLocal /findbugs-1.3.9 ./ [toto@hadoop learn]$ ls findbugs-1.3.9? hello.txt? text.txt [toto@hadoop learn]$ hadoop fs -ls / Found 6 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 03:23 /hive drwx------?? - toto supergroup????????? 0 2017-05-29 14:47 /tmp drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:59 /toto drwxr-xr-x?? - toto supergroup????????? 0 2017-05-30 00:09 /toto2 drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:36 /user [toto@hadoop learn]$ |
-cp????????????? 功能:從hdfs的一個路徑拷貝hdfs的另一個路徑 示例: hadoop ?fs ?-cp? /aaa/jdk.tar.gz? /bbb/jdk.tar.gz.2 Usage: hadoop fs [generic options] -cp [-f] [-p | -p[topax]] [-d] <src> ... <dst> [toto@hadoop learn]$ hadoop fs -cp -p /findbugs-1.3.9 /toto2 [toto@hadoop learn]$ hadoop fs -ls /toto2 Found 2 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:01 /toto2/findbugs-1.3.9 -rw-r--r--?? 3 toto supergroup??????? 149 2017-05-30 00:09 /toto2/hello.txt [toto@hadoop learn]$ ? ? -mv???????????????????? 功能:在hdfs目錄中移動文件 示例: hadoop ?fs ?-mv? /aaa/jdk.tar.gz? / 實際案例: [toto@hadoop learn]$ hadoop fs -ls /toto2 Found 2 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:01 /toto2/findbugs-1.3.9 -rw-r--r--?? 3 toto supergroup??????? 149 2017-05-30 00:09 /toto2/hello.txt [toto@hadoop learn]$ hadoop fs -mv /toto/hello.txt /user mv: `/toto/hello.txt': No such file or directory [toto@hadoop learn]$ hadoop fs -mv /toto2/hello.txt /user [toto@hadoop learn]$ hadoop fs -ls /user Found 3 items drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 23:36 /user/hadoop -rw-r--r--?? 3 toto supergroup??????? 149 2017-05-30 00:09 /user/hello.txt drwxr-xr-x?? - toto supergroup????????? 0 2017-05-29 14:51 /user/toto [toto@hadoop learn]$ |
-get????????????? 功能:等同于copyToLocal,就是從hdfs下載文件到本地 示例:hadoop fs -get? /aaa/jdk.tar.gz ????? 功能:合并下載多個文件 示例:比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 ? 刪除非空文件夾時不讓報錯的命令: hadoop fs -rmdir --ignore-fail-on-non-empty /toto2/findbugs-1.3.9/lib |
-df?????????????? 功能:統計文件系統的可用空間信息 示例:hadoop ?fs ?-df? -h ?/ [toto@hadoop learn]$ hdfs dfs -df -h / Filesystem???????????? Size???? Used? Available? Use% hdfs://hadoop:9000? 134.4 G? 472.4 M???? 97.8 G??? 0% ? ? -du 功能:統計文件夾的大小信息 示例: hadoop? fs? -du? -s? -h /aaa/* [toto@hadoop learn]$ hadoop fs -du -s -h /toto2 2.3 M? /toto2 [toto@hadoop learn]$ |
-count???????? 功能:統計一個指定目錄下的文件節點數量 示例:hadoop fs -count /aaa/ ? |
-setrep??????????????? 功能:設置hdfs中文件的副本數量 示例:hadoop fs -setrep 3 /aaa/jdk.tar.gz?? (這里的3) 實際命令: [toto@hadoop learn]$ hadoop fs -setrep 3 /toto2/findbugs-1.3.9 Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-ASM.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-bcel.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-commons-lang.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-docbook.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-dom4j.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jFormatString.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jaxen.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jcip.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jdepend.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jsr305.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-mysql-connector.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE.txt |
?
?
補充:查看dfs集群工作狀態的命令
hdfs dfsadmin -report
?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的HDFS命令行客户端使用,命令行客户端支持的命令参数,常用命令参数介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 征信记录已经结清的可以消除吗
- 下一篇: 新款哈弗h5最新消息来了,可能会使用坦克