FileSystemShell.apt.vm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. ~~ Licensed to the Apache Software Foundation (ASF) under one or more
  2. ~~ contributor license agreements. See the NOTICE file distributed with
  3. ~~ this work for additional information regarding copyright ownership.
  4. ~~ The ASF licenses this file to You under the Apache License, Version 2.0
  5. ~~ (the "License"); you may not use this file except in compliance with
  6. ~~ the License. You may obtain a copy of the License at
  7. ~~
  8. ~~ http://www.apache.org/licenses/LICENSE-2.0
  9. ~~
  10. ~~ Unless required by applicable law or agreed to in writing, software
  11. ~~ distributed under the License is distributed on an "AS IS" BASIS,
  12. ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ~~ See the License for the specific language governing permissions and
  14. ~~ limitations under the License.
  15. ---
  16. File System Shell Guide
  17. ---
  18. ---
  19. ${maven.build.timestamp}
  20. %{toc}
  21. Overview
  22. The File System (FS) shell includes various shell-like commands that
  23. directly interact with the Hadoop Distributed File System (HDFS) as well as
  24. other file systems that Hadoop supports, such as Local FS, HFTP FS, S3 FS,
  25. and others. The FS shell is invoked by:
  26. +---
  27. bin/hadoop fs <args>
  28. +---
  29. All FS shell commands take path URIs as arguments. The URI format is
  30. <<<scheme://authority/path>>>. For HDFS the scheme is <<<hdfs>>>, and for
  31. the Local FS the scheme is <<<file>>>. The scheme and authority are
  32. optional. If not specified, the default scheme specified in the
  33. configuration is used. An HDFS file or directory such as /parent/child can
  34. be specified as <<<hdfs://namenodehost/parent/child>>> or simply as
  35. <<</parent/child>>> (given that your configuration is set to point to
  36. <<<hdfs://namenodehost>>>).
  37. Most of the commands in FS shell behave like corresponding Unix commands.
  38. Differences are described with each of the commands. Error information is
  39. sent to stderr and the output is sent to stdout.
  40. cat
  41. Usage: <<<hdfs dfs -cat URI [URI ...]>>>
  42. Copies source paths to stdout.
  43. Example:
  44. * <<<hdfs dfs -cat hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2>>>
  45. * <<<hdfs dfs -cat file:///file3 /user/hadoop/file4>>>
  46. Exit Code:
  47. Returns 0 on success and -1 on error.
  48. chgrp
  49. Usage: <<<hdfs dfs -chgrp [-R] GROUP URI [URI ...]>>>
  50. Change group association of files. With -R, make the change recursively
  51. through the directory structure. The user must be the owner of files, or
  52. else a super-user. Additional information is in the
  53. {{{betterurl}Permissions Guide}}.
  54. chmod
  55. Usage: <<<hdfs dfs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI ...]>>>
  56. Change the permissions of files. With -R, make the change recursively
  57. through the directory structure. The user must be the owner of the file, or
  58. else a super-user. Additional information is in the
  59. {{{betterurl}Permissions Guide}}.
  60. chown
  61. Usage: <<<hdfs dfs -chown [-R] [OWNER][:[GROUP]] URI [URI ]>>>
  62. Change the owner of files. With -R, make the change recursively through the
  63. directory structure. The user must be a super-user. Additional information
  64. is in the {{{betterurl}Permissions Guide}}.
  65. copyFromLocal
  66. Usage: <<<hdfs dfs -copyFromLocal <localsrc> URI>>>
  67. Similar to put command, except that the source is restricted to a local
  68. file reference.
  69. copyToLocal
  70. Usage: <<<hdfs dfs -copyToLocal [-ignorecrc] [-crc] URI <localdst> >>>
  71. Similar to get command, except that the destination is restricted to a
  72. local file reference.
  73. count
  74. Usage: <<<hdfs dfs -count [-q] <paths> >>>
  75. Count the number of directories, files and bytes under the paths that match
  76. the specified file pattern. The output columns with -count are: DIR_COUNT,
  77. FILE_COUNT, CONTENT_SIZE FILE_NAME
  78. The output columns with -count -q are: QUOTA, REMAINING_QUATA, SPACE_QUOTA,
  79. REMAINING_SPACE_QUOTA, DIR_COUNT, FILE_COUNT, CONTENT_SIZE, FILE_NAME
  80. Example:
  81. * <<<hdfs dfs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2>>>
  82. * <<<hdfs dfs -count -q hdfs://nn1.example.com/file1>>>
  83. Exit Code:
  84. Returns 0 on success and -1 on error.
  85. cp
  86. Usage: <<<hdfs dfs -cp URI [URI ...] <dest> >>>
  87. Copy files from source to destination. This command allows multiple sources
  88. as well in which case the destination must be a directory.
  89. Example:
  90. * <<<hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2>>>
  91. * <<<hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir>>>
  92. Exit Code:
  93. Returns 0 on success and -1 on error.
  94. du
  95. Usage: <<<hdfs dfs -du [-s] [-h] URI [URI ...]>>>
  96. Displays sizes of files and directories contained in the given directory or
  97. the length of a file in case its just a file.
  98. Options:
  99. * The -s option will result in an aggregate summary of file lengths being
  100. displayed, rather than the individual files.
  101. * The -h option will format file sizes in a "human-readable" fashion (e.g
  102. 64.0m instead of 67108864)
  103. Example:
  104. * hdfs dfs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1
  105. Exit Code:
  106. Returns 0 on success and -1 on error.
  107. dus
  108. Usage: <<<hdfs dfs -dus <args> >>>
  109. Displays a summary of file lengths. This is an alternate form of hdfs dfs -du -s.
  110. expunge
  111. Usage: <<<hdfs dfs -expunge>>>
  112. Empty the Trash. Refer to the {{{betterurl}HDFS Architecture Guide}} for
  113. more information on the Trash feature.
  114. get
  115. Usage: <<<hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst> >>>
  116. Copy files to the local file system. Files that fail the CRC check may be
  117. copied with the -ignorecrc option. Files and CRCs may be copied using the
  118. -crc option.
  119. Example:
  120. * <<<hdfs dfs -get /user/hadoop/file localfile>>>
  121. * <<<hdfs dfs -get hdfs://nn.example.com/user/hadoop/file localfile>>>
  122. Exit Code:
  123. Returns 0 on success and -1 on error.
  124. getmerge
  125. Usage: <<<hdfs dfs -getmerge <src> <localdst> [addnl]>>>
  126. Takes a source directory and a destination file as input and concatenates
  127. files in src into the destination local file. Optionally addnl can be set to
  128. enable adding a newline character at the
  129. end of each file.
  130. ls
  131. Usage: <<<hdfs dfs -ls <args> >>>
  132. For a file returns stat on the file with the following format:
  133. +---+
  134. permissions number_of_replicas userid groupid filesize modification_date modification_time filename
  135. +---+
  136. For a directory it returns list of its direct children as in unix.A directory is listed as:
  137. +---+
  138. permissions userid groupid modification_date modification_time dirname
  139. +---+
  140. Example:
  141. * <<<hdfs dfs -ls /user/hadoop/file1>>>
  142. Exit Code:
  143. Returns 0 on success and -1 on error.
  144. lsr
  145. Usage: <<<hdfs dfs -lsr <args> >>>
  146. Recursive version of ls. Similar to Unix ls -R.
  147. mkdir
  148. Usage: <<<hdfs dfs -mkdir [-p] <paths> >>>
  149. Takes path uri's as argument and creates directories. With -p the behavior
  150. is much like unix mkdir -p creating parent directories along the path.
  151. Example:
  152. * <<<hdfs dfs -mkdir /user/hadoop/dir1 /user/hadoop/dir2>>>
  153. * <<<hdfs dfs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir>>>
  154. Exit Code:
  155. Returns 0 on success and -1 on error.
  156. moveFromLocal
  157. Usage: <<<dfs -moveFromLocal <localsrc> <dst> >>>
  158. Similar to put command, except that the source localsrc is deleted after
  159. it's copied.
  160. moveToLocal
  161. Usage: <<<hdfs dfs -moveToLocal [-crc] <src> <dst> >>>
  162. Displays a "Not implemented yet" message.
  163. mv
  164. Usage: <<<hdfs dfs -mv URI [URI ...] <dest> >>>
  165. Moves files from source to destination. This command allows multiple sources
  166. as well in which case the destination needs to be a directory. Moving files
  167. across file systems is not permitted.
  168. Example:
  169. * <<<hdfs dfs -mv /user/hadoop/file1 /user/hadoop/file2>>>
  170. * <<<hdfs dfs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/file3 hdfs://nn.example.com/dir1>>>
  171. Exit Code:
  172. Returns 0 on success and -1 on error.
  173. put
  174. Usage: <<<hdfs dfs -put <localsrc> ... <dst> >>>
  175. Copy single src, or multiple srcs from local file system to the destination
  176. file system. Also reads input from stdin and writes to destination file
  177. system.
  178. * <<<hdfs dfs -put localfile /user/hadoop/hadoopfile>>>
  179. * <<<hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir>>>
  180. * <<<hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile>>>
  181. * <<<hdfs dfs -put - hdfs://nn.example.com/hadoop/hadoopfile>>>
  182. Reads the input from stdin.
  183. Exit Code:
  184. Returns 0 on success and -1 on error.
  185. rm
  186. Usage: <<<hdfs dfs -rm [-skipTrash] URI [URI ...]>>>
  187. Delete files specified as args. Only deletes non empty directory and files.
  188. If the -skipTrash option is specified, the trash, if enabled, will be
  189. bypassed and the specified file(s) deleted immediately. This can be useful
  190. when it is necessary to delete files from an over-quota directory. Refer to
  191. rmr for recursive deletes.
  192. Example:
  193. * <<<hdfs dfs -rm hdfs://nn.example.com/file /user/hadoop/emptydir>>>
  194. Exit Code:
  195. Returns 0 on success and -1 on error.
  196. rmr
  197. Usage: <<<hdfs dfs -rmr [-skipTrash] URI [URI ...]>>>
  198. Recursive version of delete. If the -skipTrash option is specified, the
  199. trash, if enabled, will be bypassed and the specified file(s) deleted
  200. immediately. This can be useful when it is necessary to delete files from an
  201. over-quota directory.
  202. Example:
  203. * <<<hdfs dfs -rmr /user/hadoop/dir>>>
  204. * <<<hdfs dfs -rmr hdfs://nn.example.com/user/hadoop/dir>>>
  205. Exit Code:
  206. Returns 0 on success and -1 on error.
  207. setrep
  208. Usage: <<<hdfs dfs -setrep [-R] <path> >>>
  209. Changes the replication factor of a file. -R option is for recursively
  210. increasing the replication factor of files within a directory.
  211. Example:
  212. * <<<hdfs dfs -setrep -w 3 -R /user/hadoop/dir1>>>
  213. Exit Code:
  214. Returns 0 on success and -1 on error.
  215. stat
  216. Usage: <<<hdfs dfs -stat URI [URI ...]>>>
  217. Returns the stat information on the path.
  218. Example:
  219. * <<<hdfs dfs -stat path>>>
  220. Exit Code:
  221. Returns 0 on success and -1 on error.
  222. tail
  223. Usage: <<<hdfs dfs -tail [-f] URI>>>
  224. Displays last kilobyte of the file to stdout. -f option can be used as in
  225. Unix.
  226. Example:
  227. * <<<hdfs dfs -tail pathname>>>
  228. Exit Code:
  229. Returns 0 on success and -1 on error.
  230. test
  231. Usage: <<<hdfs dfs -test -[ezd] URI>>>
  232. Options:
  233. *----+------------+
  234. | -e | check to see if the file exists. Return 0 if true.
  235. *----+------------+
  236. | -z | check to see if the file is zero length. Return 0 if true.
  237. *----+------------+
  238. | -d | check to see if the path is directory. Return 0 if true.
  239. *----+------------+
  240. Example:
  241. * <<<hdfs dfs -test -e filename>>>
  242. text
  243. Usage: <<<hdfs dfs -text <src> >>>
  244. Takes a source file and outputs the file in text format. The allowed formats
  245. are zip and TextRecordInputStream.
  246. touchz
  247. Usage: <<<hdfs dfs -touchz URI [URI ...]>>>
  248. Create a file of zero length.
  249. Example:
  250. * <<<hadoop -touchz pathname>>>
  251. Exit Code:
  252. Returns 0 on success and -1 on error.