Changes between Version 3 and Version 4 of waue/2009/0403


Ignore:
Timestamp:
Apr 3, 2009, 5:00:09 PM (15 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2009/0403

    v3 v4  
    2020dfs.umask = 022
    2121}}}
     22
     23= HDFS shell 的用法=
     24 * bin/hadoop dfs <args> ,以下就是 <args> 的介紹
     25 * 以下操作基本在
     26
     27== -cat ==
     28 * 將路徑指定文件的內容輸出到stdout
     29{{{
     30$ bin/hadoop dfs -cat quota/hadoop-env.sh
     31}}}
     32== -chgrp ==
     33 * 改變文件所屬的組
     34{{{
     35$ bin/hadoop dfs -chgrp -R waue own
     36}}}
     37== -chmod ==
     38 * 改變文件的權限
     39{{{
     40$ bin/hadoop dfs -chmod -R 755 own
     41}}}
     42== -chown==
     43 * 改變文件的擁有者
     44{{{
     45$ bin/hadoop dfs -chown -R waue own
     46}}}
     47== -copyFromLocal, -put==
     48 * 從local放檔案到hdfs
     49{{{
     50$ bin/hadoop dfs -put input dfs_input
     51}}}
     52== -copyToLocal, -get==
     53 * 把hdfs上得檔案下載到 local
     54{{{
     55$ bin/hadoop dfs -get dfs_input input1
     56}}}
     57== -cp==
     58 * 將文件從hdfs原本路徑複製到hdfs目標路徑
     59{{{
     60$ bin/hadoop dfs -cp own waue
     61}}}
     62== -du==
     63 * 顯示目錄中所有文件的大小
     64{{{
     65$ bin/hadoop dfs -du input
     66
     67Found 4 items
     68
     69115045564   hdfs://gm1.nchc.org.tw:9000/user/waue/input/1.txt
     70
     71987864      hdfs://gm1.nchc.org.tw:9000/user/waue/input/2.txt
     72
     731573048     hdfs://gm1.nchc.org.tw:9000/user/waue/input/3.txt
     74
     7525844527    hdfs://gm1.nchc.org.tw:9000/user/waue/input/4.txt
     76}}}
     77== -dus==
     78 * 顯示該目錄/文件的總大小
     79{{{
     80$ bin/hadoop dfs -dus input
     81
     82hdfs://gm1.nchc.org.tw:9000/user/waue/input     143451003
     83}}}
     84== -expunge==
     85 * 清空垃圾桶
     86{{{
     87$ bin/hadoop fs -expunge
     88}}}
     89== -getmerge==
     90 * 將來源目錄<src>下所有的文件都集合到本地端一個<localdst>檔案內
     91 * bin/hadoop fs -getmerge <src> <localdst>
     92{{{
     93$ echo "this is one; " >> in1/input
     94$ echo "this is two; " >> in1/input2
     95$ bin/hadoop dfs -put in1 in1
     96$ bin/hadoop dfs -getmerge in1 merge.txt
     97$ cat ./merge.txt
     98}}}
     99
     100== -ls==
     101 * 列出文件或目錄的資訊
     102 * 文件名 <副本數> 文件大小 修改日期 修改時間 權限 用戶ID 組ID
     103 * 目錄名 <dir> 修改日期 修改時間 權限 用戶ID 組ID
     104{{{
     105$ bin/hadoop dfs -ls
     106}}}
     107== -lsr ==
     108 * ls命令的遞迴版本
     109{{{
     110$ bin/hadoop dfs -lsr /
     111}}}
     112== -mkdir ==
     113 * 建立資料夾
     114{{{
     115$ bin/hadoop dfs -mkdir a b c
     116}}}
     117== -moveFromLocal==
     118 * 將local端的資料夾剪下移動到hdfs上
     119{{{
     120$ bin/hadoop dfs -moveFromLocal in1 in2
     121}}}
     122== -mv==
     123 * 更改資料的名稱
     124{{{
     125$ bin/hadoop dfs -mv in2 in3
     126}}}
     127== -rm ==
     128 * 刪除指定的檔案(不可資料夾)
     129{{{
     130$ bin/hadoop dfs -rm in1/input
     131}}}
     132== -rmr ==
     133 * 遞迴刪除資料夾(包含在內的所有檔案)
     134{{{
     135$ bin/hadoop dfs -rmr in1
     136}}}
     137== -setrep ==
     138 * 設定副本系數
     139 * bin/hadoop fs -setrep [-R] [-w] <rep> <path/file>
     140{{{
     141$ bin/hadoop fs -setrep -w 2 -R input
     142
     143Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/waue/input/1.txt
     144
     145Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/waue/input/2.txt
     146
     147Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/waue/input/3.txt
     148
     149Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/waue/input/4.txt
     150
     151Waiting for hdfs://gm1.nchc.org.tw:9000/user/waue/input/1.txt ... done
     152
     153Waiting for hdfs://gm1.nchc.org.tw:9000/user/waue/input/2.txt ... done
     154
     155Waiting for hdfs://gm1.nchc.org.tw:9000/user/waue/input/3.txt ... done
     156
     157Waiting for hdfs://gm1.nchc.org.tw:9000/user/waue/input/4.txt ... done
     158}}}
     159== -stat ==
     160 * 印出時間資訊
     161{{{
     162$ bin/hadoop fs -stat input
     163
     1642009-04-02 03:51:29
     165}}}
     166== -tail==
     167 * 將文件的最後1k內容輸出
     168 * 用法 : bin/hadoop fs -tail [-f] 檔案 (-f 參數用來顯示如果檔案增大,則秀出被append上得內容)
     169{{{
     170$ bin/hadoop dfs -tail input/1.txt
     171}}}
     172== -test ==
     173 * 測試檔案, -e 檢查文件是否存在(1=存在, 0=否), -z 檢查文件是否為空(1=空, 0=不為空), -d 檢查是否為目錄(1=存在, 0=否)
     174   * 要用echo $? 來看回傳值為 0 or 1
     175 * 用法: bin/hadoop fs -test -[ezd] URI
     176 
     177{{{
     178$ bin/hadoop dfs -test -e /user/waue/input/5.txt
     179$ bin/hadoop dfs -test -z /user/waue/input/5.txt
     180test: File does not exist: /user/waue/input/5.txt
     181$ bin/hadoop dfs -test -d /user/waue/input/5.txt
     182
     183test: File does not exist: /user/waue/input/5.txt
     184}}}
     185== -text ==
     186 * 將檔案(如zip, textrecordinputstream)輸出為純文字格式
     187 * hadoop fs -text <src>
     188 ps : 測試出來的結果怪怪的,
     189{{{
     190$ bin/hadoop dfs -text b/a.txt.zip
     191
     192PK
     193
     194���:��H{
     195
     196
     197
     198        a.txtUT        b��Ib��IUx��sssss
     199
     200test
     201
     202PK
     203
     204���:��H{
     205
     206
     207
     208��a.txtUTb��IUxPK@C
     209}}}
     210== -touchz==
     211 *
     212{{{
     213$ bin/hadoop dfs -touchz b/kk
     214$ bin/hadoop dfs -test -z b/kk
     215
     216$ echo $?
     217
     2181
     219
     220$ bin/hadoop dfs -test -z b/a.txt.zip
     221
     222$ echo $?
     223
     2240
     225
     226
     227}}}