close
Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": libsvn_ra_serf-1.so.1: failed to map segment from shared object: Cannot allocate memory). Look in the Trac log for more information.
- Timestamp:
-
Apr 19, 2011, 8:48:49 AM (15 years ago)
- Author:
-
jazz
- Comment:
-
--
Legend:
- Unmodified
- Added
- Removed
- Modified
-
|
v1
|
v2
|
|
| 10 | 10 | }}} |
| 11 | 11 | |
| | 12 | * 以下練習,請連線至 hadoop.nchc.org.tw 操作。 |
| | 13 | |
| 12 | 14 | == Content 1: HDFS Shell 基本操作 == |
| 13 | 15 | == Content 1: Basic HDFS Shell Commands == |
| … |
… |
|
| 17 | 19 | |
| 18 | 20 | {{{ |
| 19 | | /opt/hadoop$ bin/hadoop fs -ls |
| 20 | | /opt/hadoop$ bin/hadoop fs -lsr |
| | 21 | ~$ hadoop fs -ls |
| | 22 | ~$ hadoop fs -lsr |
| 21 | 23 | }}} |
| 22 | 24 | |
| … |
… |
|
| 27 | 29 | |
| 28 | 30 | {{{ |
| 29 | | /opt/hadoop$ bin/hadoop fs -put conf input |
| | 31 | ~$ hadoop fs -put conf input |
| 30 | 32 | }}} |
| 31 | 33 | |
| … |
… |
|
| 33 | 35 | |
| 34 | 36 | {{{ |
| 35 | | /opt/hadoop$ bin/hadoop fs -ls |
| 36 | | /opt/hadoop$ bin/hadoop fs -ls input |
| | 37 | ~$ hadoop fs -ls |
| | 38 | ~$ hadoop fs -ls input |
| 37 | 39 | }}} |
| 38 | 40 | |
| … |
… |
|
| 43 | 45 | |
| 44 | 46 | {{{ |
| 45 | | /opt/hadoop$ bin/hadoop fs -get input fromHDFS |
| | 47 | ~$ hadoop fs -get input fromHDFS |
| 46 | 48 | }}} |
| 47 | 49 | |
| … |
… |
|
| 49 | 51 | |
| 50 | 52 | {{{ |
| 51 | | /opt/hadoop$ ls -al | grep fromHDFS |
| 52 | | /opt/hadoop$ ls -al fromHDFS |
| | 53 | ~$ ls -al | grep fromHDFS |
| | 54 | ~$ ls -al fromHDFS |
| 53 | 55 | }}} |
| 54 | 56 | |
| … |
… |
|
| 57 | 59 | |
| 58 | 60 | {{{ |
| 59 | | /opt/hadoop$ bin/hadoop fs -ls input |
| 60 | | /opt/hadoop$ bin/hadoop fs -rm input/masters |
| | 61 | ~$ hadoop fs -ls input |
| | 62 | ~$ hadoop fs -rm input/masters |
| 61 | 63 | }}} |
| 62 | 64 | |
| … |
… |
|
| 65 | 67 | |
| 66 | 68 | {{{ |
| 67 | | /opt/hadoop$ bin/hadoop fs -ls input |
| 68 | | /opt/hadoop$ bin/hadoop fs -cat input/slaves |
| | 69 | ~$ hadoop fs -ls input |
| | 70 | ~$ hadoop fs -cat input/slaves |
| 69 | 71 | }}} |
| 70 | 72 | |
| … |
… |
|
| 73 | 75 | |
| 74 | 76 | {{{ |
| 75 | | hadooper@vPro:/opt/hadoop$ bin/hadoop fs |
| | 77 | hadooper@vPro:~$ hadoop fs |
| 76 | 78 | |
| 77 | 79 | Usage: java FsShell |
| … |
… |
|
| 115 | 117 | -archives <comma separated list of archives> specify comma separated archives to be unarchived on the compute machines. |
| 116 | 118 | The general command line syntax is |
| 117 | | bin/hadoop command [genericOptions] [commandOptions] |
| | 119 | hadoop command [genericOptions] [commandOptions] |
| 118 | 120 | }}} |
| 119 | 121 | |
| … |
… |
|
| 127 | 129 | == Content 3: More about HDFS Shell == |
| 128 | 130 | |
| 129 | | * bin/hadoop fs <args> ,下面則列出 <args> 的用法[[BR]]Following are the examples of hadoop fs related commands. |
| | 131 | * hadoop fs <args> ,下面則列出 <args> 的用法[[BR]]Following are the examples of hadoop fs related commands. |
| 130 | 132 | * 以下操作預設的目錄在 /user/<$username>/ 下[[BR]]By default, your working directory will be at /user/<$username>/. |
| 131 | 133 | {{{ |
| 132 | | $ bin/hadoop fs -ls input |
| | 134 | $ hadoop fs -ls input |
| 133 | 135 | Found 4 items |
| 134 | 136 | -rw-r--r-- 2 hadooper supergroup 115045564 2009-04-02 11:51 /user/hadooper/input/1.txt |
| … |
… |
|
| 139 | 141 | * 完整的路徑則是 '''hdfs://node:port/path''' 如:[[BR]]Or you have to give a __''absolute path''__, such as '''hdfs://node:port/path''' |
| 140 | 142 | {{{ |
| 141 | | $ bin/hadoop fs -ls hdfs://gm1.nchc.org.tw:9000/user/hadooper/input |
| | 143 | $ hadoop fs -ls hdfs://gm1.nchc.org.tw:9000/user/hadooper/input |
| 142 | 144 | Found 4 items |
| 143 | 145 | -rw-r--r-- 2 hadooper supergroup 115045564 2009-04-02 11:51 /user/hadooper/input/1.txt |
| … |
… |
|
| 151 | 153 | * 將路徑指定文件的內容輸出到 STDOUT [[BR]] Print given file content to STDOUT |
| 152 | 154 | {{{ |
| 153 | | $ bin/hadoop fs -cat quota/hadoop-env.sh |
| | 155 | $ hadoop fs -cat quota/hadoop-env.sh |
| 154 | 156 | }}} |
| 155 | 157 | |
| … |
… |
|
| 158 | 160 | * 改變文件所屬的組 [[BR]] Change '''owner group''' of given file or folder |
| 159 | 161 | {{{ |
| 160 | | $ bin/hadoop fs -chgrp -R hadooper own |
| | 162 | $ hadoop fs -chgrp -R hadooper own |
| 161 | 163 | }}} |
| 162 | 164 | |
| … |
… |
|
| 165 | 167 | * 改變文件的權限 [[BR]] Change '''read and write permission''' of given file or folder |
| 166 | 168 | {{{ |
| 167 | | $ bin/hadoop fs -chmod -R 755 own |
| | 169 | $ hadoop fs -chmod -R 755 own |
| 168 | 170 | }}} |
| 169 | 171 | |
| … |
… |
|
| 172 | 174 | * 改變文件的擁有者 [[BR]] Change '''owner''' of given file or folder |
| 173 | 175 | {{{ |
| 174 | | $ bin/hadoop fs -chown -R hadooper own |
| | 176 | $ hadoop fs -chown -R hadooper own |
| 175 | 177 | }}} |
| 176 | 178 | |
| … |
… |
|
| 179 | 181 | * 從 local 放檔案到 hdfs [[BR]] Both commands will copy given file or folder from local to HDFS |
| 180 | 182 | {{{ |
| 181 | | $ bin/hadoop fs -put input dfs_input |
| | 183 | $ hadoop fs -put input dfs_input |
| 182 | 184 | }}} |
| 183 | 185 | |
| … |
… |
|
| 186 | 188 | * 把hdfs上得檔案下載到 local [[BR]] Both commands will copy given file or folder from HDFS to local |
| 187 | 189 | {{{ |
| 188 | | $ bin/hadoop fs -get dfs_input input1 |
| | 190 | $ hadoop fs -get dfs_input input1 |
| 189 | 191 | }}} |
| 190 | 192 | |
| … |
… |
|
| 193 | 195 | * 將文件從 hdfs 原本路徑複製到 hdfs 目標路徑 [[BR]] Copy given file or folder from HDFS source path to HDFS target path |
| 194 | 196 | {{{ |
| 195 | | $ bin/hadoop fs -cp own hadooper |
| | 197 | $ hadoop fs -cp own hadooper |
| 196 | 198 | }}} |
| 197 | 199 | |
| … |
… |
|
| 200 | 202 | * 顯示目錄中所有文件的大小 [[BR]] Display the size of files in given folder |
| 201 | 203 | {{{ |
| 202 | | $ bin/hadoop fs -du input |
| | 204 | $ hadoop fs -du input |
| 203 | 205 | |
| 204 | 206 | Found 4 items |
| … |
… |
|
| 212 | 214 | * 顯示該目錄/文件的總大小 [[BR]] Display total size of given folder |
| 213 | 215 | {{{ |
| 214 | | $ bin/hadoop fs -dus input |
| | 216 | $ hadoop fs -dus input |
| 215 | 217 | |
| 216 | 218 | hdfs://gm1.nchc.org.tw:9000/user/hadooper/input 143451003 |
| … |
… |
|
| 221 | 223 | * 清空垃圾桶 [[BR]] Clean up Recycled |
| 222 | 224 | {{{ |
| 223 | | $ bin/hadoop fs -expunge |
| | 225 | $ hadoop fs -expunge |
| 224 | 226 | }}} |
| 225 | 227 | |
| … |
… |
|
| 228 | 230 | * 將來源目錄<src>下所有的文件都集合到本地端一個<localdst>檔案內 [[BR]] Merge all files in HDFS source folder <src> into one local file |
| 229 | 231 | {{{ |
| 230 | | $ bin/hadoop fs -getmerge <src> <localdst> |
| | 232 | $ hadoop fs -getmerge <src> <localdst> |
| 231 | 233 | }}} |
| 232 | 234 | {{{ |
| 233 | 235 | $ echo "this is one; " >> in1/input |
| 234 | 236 | $ echo "this is two; " >> in1/input2 |
| 235 | | $ bin/hadoop fs -put in1 in1 |
| 236 | | $ bin/hadoop fs -getmerge in1 merge.txt |
| | 237 | $ hadoop fs -put in1 in1 |
| | 238 | $ hadoop fs -getmerge in1 merge.txt |
| 237 | 239 | $ cat ./merge.txt |
| 238 | 240 | }}} |
| … |
… |
|
| 244 | 246 | * 目錄名 <dir> 修改日期 修改時間 權限 用戶ID 組ID [[BR]] <folder name> <modified date> <modified time> <permission> <user id> <group id> |
| 245 | 247 | {{{ |
| 246 | | $ bin/hadoop fs -ls |
| | 248 | $ hadoop fs -ls |
| 247 | 249 | }}} |
| 248 | 250 | |
| … |
… |
|
| 251 | 253 | * ls 命令的遞迴版本 [[BR]] list files and folders with recursive |
| 252 | 254 | {{{ |
| 253 | | $ bin/hadoop fs -lsr / |
| | 255 | $ hadoop fs -lsr / |
| 254 | 256 | }}} |
| 255 | 257 | |
| … |
… |
|
| 258 | 260 | * 建立資料夾 [[BR]] create directories |
| 259 | 261 | {{{ |
| 260 | | $ bin/hadoop fs -mkdir a b c |
| | 262 | $ hadoop fs -mkdir a b c |
| 261 | 263 | }}} |
| 262 | 264 | |
| … |
… |
|
| 265 | 267 | * 將 local 端的資料夾剪下移動到 hdfs 上 [[BR]] move local files or folder to HDFS ( it will delete local files or folder. ) |
| 266 | 268 | {{{ |
| 267 | | $ bin/hadoop fs -moveFromLocal in1 in2 |
| | 269 | $ hadoop fs -moveFromLocal in1 in2 |
| 268 | 270 | }}} |
| 269 | 271 | |
| … |
… |
|
| 272 | 274 | * 更改資料的名稱 [[BR]] Change file name or folder name. |
| 273 | 275 | {{{ |
| 274 | | $ bin/hadoop fs -mv in2 in3 |
| | 276 | $ hadoop fs -mv in2 in3 |
| 275 | 277 | }}} |
| 276 | 278 | |
| … |
… |
|
| 279 | 281 | * 刪除指定的檔案(不可資料夾)[[BR]] Remove given files (not folders) |
| 280 | 282 | {{{ |
| 281 | | $ bin/hadoop fs -rm in1/input |
| | 283 | $ hadoop fs -rm in1/input |
| 282 | 284 | }}} |
| 283 | 285 | === -rmr === |
| … |
… |
|
| 285 | 287 | * 遞迴刪除資料夾(包含在內的所有檔案) [[BR]] Remove given files and folders with recursive |
| 286 | 288 | {{{ |
| 287 | | $ bin/hadoop fs -rmr in1 |
| | 289 | $ hadoop fs -rmr in1 |
| 288 | 290 | }}} |
| 289 | 291 | |
| … |
… |
|
| 292 | 294 | * 設定副本係數 [[BR]] setup replication numbers of given files or folder |
| 293 | 295 | {{{ |
| 294 | | $ bin/hadoop fs -setrep [-R] [-w] <rep> <path/file> |
| 295 | | }}} |
| 296 | | {{{ |
| 297 | | $ bin/hadoop fs -setrep -w 2 -R input |
| | 296 | $ hadoop fs -setrep [-R] [-w] <rep> <path/file> |
| | 297 | }}} |
| | 298 | {{{ |
| | 299 | $ hadoop fs -setrep -w 2 -R input |
| 298 | 300 | Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/1.txt |
| 299 | 301 | Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/2.txt |
| … |
… |
|
| 310 | 312 | * 印出時間資訊 [[BR]] Print Status of time stamp of folder |
| 311 | 313 | {{{ |
| 312 | | $ bin/hadoop fs -stat input |
| | 314 | $ hadoop fs -stat input |
| 313 | 315 | 2009-04-02 03:51:29 |
| 314 | 316 | }}} |
| … |
… |
|
| 318 | 320 | * 用法 Usage |
| 319 | 321 | {{{ |
| 320 | | bin/hadoop fs -tail [-f] 檔案 (-f 參數用來顯示如果檔案增大,則秀出被append上得內容) |
| 321 | | bin/hadoop fs -tail [-f] <path/file> (-f is used when file had appended) |
| 322 | | }}} |
| 323 | | {{{ |
| 324 | | $ bin/hadoop fs -tail input/1.txt |
| | 322 | hadoop fs -tail [-f] 檔案 (-f 參數用來顯示如果檔案增大,則秀出被append上得內容) |
| | 323 | hadoop fs -tail [-f] <path/file> (-f is used when file had appended) |
| | 324 | }}} |
| | 325 | {{{ |
| | 326 | $ hadoop fs -tail input/1.txt |
| 325 | 327 | }}} |
| 326 | 328 | |
| … |
… |
|
| 331 | 333 | * 用法 Usage |
| 332 | 334 | {{{ |
| 333 | | $ bin/hadoop fs -test -[ezd] URI |
| 334 | | }}} |
| 335 | | |
| 336 | | {{{ |
| 337 | | $ bin/hadoop fs -test -e /user/hadooper/input/5.txt |
| 338 | | $ bin/hadoop fs -test -z /user/hadooper/input/5.txt |
| | 335 | $ hadoop fs -test -[ezd] URI |
| | 336 | }}} |
| | 337 | |
| | 338 | {{{ |
| | 339 | $ hadoop fs -test -e /user/hadooper/input/5.txt |
| | 340 | $ hadoop fs -test -z /user/hadooper/input/5.txt |
| 339 | 341 | test: File does not exist: /user/hadooper/input/5.txt |
| 340 | | $ bin/hadoop fs -test -d /user/hadooper/input/5.txt |
| | 342 | $ hadoop fs -test -d /user/hadooper/input/5.txt |
| 341 | 343 | |
| 342 | 344 | test: File does not exist: /user/hadooper/input/5.txt |
| … |
… |
|
| 356 | 358 | * ps : 目前沒支援zip的函式庫 [[BR]] PS. It does not support zip files yet. |
| 357 | 359 | {{{ |
| 358 | | $ bin/hadoop fs -text b/a.txt.zip |
| | 360 | $ hadoop fs -text b/a.txt.zip |
| 359 | 361 | PK |
| 360 | 362 | ���:��H{ |
| … |
… |
|
| 370 | 372 | * 建立一個空文件 [[BR]] creat an empty file |
| 371 | 373 | {{{ |
| 372 | | $ bin/hadoop fs -touchz b/kk |
| 373 | | $ bin/hadoop fs -test -z b/kk |
| | 374 | $ hadoop fs -touchz b/kk |
| | 375 | $ hadoop fs -test -z b/kk |
| 374 | 376 | $ echo $? |
| 375 | 377 | 1 |
| 376 | | $ bin/hadoop fs -test -z b/a.txt.zip |
| | 378 | $ hadoop fs -test -z b/a.txt.zip |
| 377 | 379 | $ echo $? |
| 378 | 380 | 0 |