FileSystemShell.apt.vm 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. appendToFile
  41. Usage: <<<hdfs dfs -appendToFile <localsrc> ... <dst> >>>
  42. Append single src, or multiple srcs from local file system to the
  43. destination file system. Also reads input from stdin and appends to
  44. destination file system.
  45. * <<<hdfs dfs -appendToFile localfile /user/hadoop/hadoopfile>>>
  46. * <<<hdfs dfs -appendToFile localfile1 localfile2 /user/hadoop/hadoopfile>>>
  47. * <<<hdfs dfs -appendToFile localfile hdfs://nn.example.com/hadoop/hadoopfile>>>
  48. * <<<hdfs dfs -appendToFile - hdfs://nn.example.com/hadoop/hadoopfile>>>
  49. Reads the input from stdin.
  50. Exit Code:
  51. Returns 0 on success and 1 on error.
  52. cat
  53. Usage: <<<hdfs dfs -cat URI [URI ...]>>>
  54. Copies source paths to stdout.
  55. Example:
  56. * <<<hdfs dfs -cat hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2>>>
  57. * <<<hdfs dfs -cat file:///file3 /user/hadoop/file4>>>
  58. Exit Code:
  59. Returns 0 on success and -1 on error.
  60. chgrp
  61. Usage: <<<hdfs dfs -chgrp [-R] GROUP URI [URI ...]>>>
  62. Change group association of files. The user must be the owner of files, or
  63. else a super-user. Additional information is in the
  64. {{{../hadoop-hdfs/HdfsPermissionsGuide.html}Permissions Guide}}.
  65. Options
  66. * The -R option will make the change recursively through the directory structure.
  67. chmod
  68. Usage: <<<hdfs dfs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI ...]>>>
  69. Change the permissions of files. With -R, make the change recursively
  70. through the directory structure. The user must be the owner of the file, or
  71. else a super-user. Additional information is in the
  72. {{{../hadoop-hdfs/HdfsPermissionsGuide.html}Permissions Guide}}.
  73. Options
  74. * The -R option will make the change recursively through the directory structure.
  75. chown
  76. Usage: <<<hdfs dfs -chown [-R] [OWNER][:[GROUP]] URI [URI ]>>>
  77. Change the owner of files. The user must be a super-user. Additional information
  78. is in the {{{../hadoop-hdfs/HdfsPermissionsGuide.html}Permissions Guide}}.
  79. Options
  80. * The -R option will make the change recursively through the directory structure.
  81. copyFromLocal
  82. Usage: <<<hdfs dfs -copyFromLocal <localsrc> URI>>>
  83. Similar to put command, except that the source is restricted to a local
  84. file reference.
  85. Options:
  86. * The -f option will overwrite the destination if it already exists.
  87. copyToLocal
  88. Usage: <<<hdfs dfs -copyToLocal [-ignorecrc] [-crc] URI <localdst> >>>
  89. Similar to get command, except that the destination is restricted to a
  90. local file reference.
  91. count
  92. Usage: <<<hdfs dfs -count [-q] <paths> >>>
  93. Count the number of directories, files and bytes under the paths that match
  94. the specified file pattern. The output columns with -count are: DIR_COUNT,
  95. FILE_COUNT, CONTENT_SIZE FILE_NAME
  96. The output columns with -count -q are: QUOTA, REMAINING_QUATA, SPACE_QUOTA,
  97. REMAINING_SPACE_QUOTA, DIR_COUNT, FILE_COUNT, CONTENT_SIZE, FILE_NAME
  98. Example:
  99. * <<<hdfs dfs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2>>>
  100. * <<<hdfs dfs -count -q hdfs://nn1.example.com/file1>>>
  101. Exit Code:
  102. Returns 0 on success and -1 on error.
  103. cp
  104. Usage: <<<hdfs dfs -cp [-f] URI [URI ...] <dest> >>>
  105. Copy files from source to destination. This command allows multiple sources
  106. as well in which case the destination must be a directory.
  107. Options:
  108. * The -f option will overwrite the destination if it already exists.
  109. Example:
  110. * <<<hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2>>>
  111. * <<<hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir>>>
  112. Exit Code:
  113. Returns 0 on success and -1 on error.
  114. du
  115. Usage: <<<hdfs dfs -du [-s] [-h] URI [URI ...]>>>
  116. Displays sizes of files and directories contained in the given directory or
  117. the length of a file in case its just a file.
  118. Options:
  119. * The -s option will result in an aggregate summary of file lengths being
  120. displayed, rather than the individual files.
  121. * The -h option will format file sizes in a "human-readable" fashion (e.g
  122. 64.0m instead of 67108864)
  123. Example:
  124. * hdfs dfs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1
  125. Exit Code:
  126. Returns 0 on success and -1 on error.
  127. dus
  128. Usage: <<<hdfs dfs -dus <args> >>>
  129. Displays a summary of file lengths. This is an alternate form of hdfs dfs -du -s.
  130. expunge
  131. Usage: <<<hdfs dfs -expunge>>>
  132. Empty the Trash. Refer to the {{{../hadoop-hdfs/HdfsDesign.html}
  133. HDFS Architecture Guide}} for more information on the Trash feature.
  134. get
  135. Usage: <<<hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst> >>>
  136. Copy files to the local file system. Files that fail the CRC check may be
  137. copied with the -ignorecrc option. Files and CRCs may be copied using the
  138. -crc option.
  139. Example:
  140. * <<<hdfs dfs -get /user/hadoop/file localfile>>>
  141. * <<<hdfs dfs -get hdfs://nn.example.com/user/hadoop/file localfile>>>
  142. Exit Code:
  143. Returns 0 on success and -1 on error.
  144. getfacl
  145. Usage: <<<hdfs dfs -getfacl [-R] <path> >>>
  146. Displays the Access Control Lists (ACLs) of files and directories. If a
  147. directory has a default ACL, then getfacl also displays the default ACL.
  148. Options:
  149. * -R: List the ACLs of all files and directories recursively.
  150. * <path>: File or directory to list.
  151. Examples:
  152. * <<<hdfs dfs -getfacl /file>>>
  153. * <<<hdfs dfs -getfacl -R /dir>>>
  154. Exit Code:
  155. Returns 0 on success and non-zero on error.
  156. getmerge
  157. Usage: <<<hdfs dfs -getmerge <src> <localdst> [addnl]>>>
  158. Takes a source directory and a destination file as input and concatenates
  159. files in src into the destination local file. Optionally addnl can be set to
  160. enable adding a newline character at the
  161. end of each file.
  162. ls
  163. Usage: <<<hdfs dfs -ls <args> >>>
  164. For a file returns stat on the file with the following format:
  165. +---+
  166. permissions number_of_replicas userid groupid filesize modification_date modification_time filename
  167. +---+
  168. For a directory it returns list of its direct children as in Unix. A directory is listed as:
  169. +---+
  170. permissions userid groupid modification_date modification_time dirname
  171. +---+
  172. Example:
  173. * <<<hdfs dfs -ls /user/hadoop/file1>>>
  174. Exit Code:
  175. Returns 0 on success and -1 on error.
  176. lsr
  177. Usage: <<<hdfs dfs -lsr <args> >>>
  178. Recursive version of ls. Similar to Unix ls -R.
  179. mkdir
  180. Usage: <<<hdfs dfs -mkdir [-p] <paths> >>>
  181. Takes path uri's as argument and creates directories.
  182. Options:
  183. * The -p option behavior is much like Unix mkdir -p, creating parent directories along the path.
  184. Example:
  185. * <<<hdfs dfs -mkdir /user/hadoop/dir1 /user/hadoop/dir2>>>
  186. * <<<hdfs dfs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir>>>
  187. Exit Code:
  188. Returns 0 on success and -1 on error.
  189. moveFromLocal
  190. Usage: <<<dfs -moveFromLocal <localsrc> <dst> >>>
  191. Similar to put command, except that the source localsrc is deleted after
  192. it's copied.
  193. moveToLocal
  194. Usage: <<<hdfs dfs -moveToLocal [-crc] <src> <dst> >>>
  195. Displays a "Not implemented yet" message.
  196. mv
  197. Usage: <<<hdfs dfs -mv URI [URI ...] <dest> >>>
  198. Moves files from source to destination. This command allows multiple sources
  199. as well in which case the destination needs to be a directory. Moving files
  200. across file systems is not permitted.
  201. Example:
  202. * <<<hdfs dfs -mv /user/hadoop/file1 /user/hadoop/file2>>>
  203. * <<<hdfs dfs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/file3 hdfs://nn.example.com/dir1>>>
  204. Exit Code:
  205. Returns 0 on success and -1 on error.
  206. put
  207. Usage: <<<hdfs dfs -put <localsrc> ... <dst> >>>
  208. Copy single src, or multiple srcs from local file system to the destination
  209. file system. Also reads input from stdin and writes to destination file
  210. system.
  211. * <<<hdfs dfs -put localfile /user/hadoop/hadoopfile>>>
  212. * <<<hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir>>>
  213. * <<<hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile>>>
  214. * <<<hdfs dfs -put - hdfs://nn.example.com/hadoop/hadoopfile>>>
  215. Reads the input from stdin.
  216. Exit Code:
  217. Returns 0 on success and -1 on error.
  218. rm
  219. Usage: <<<hdfs dfs -rm [-skipTrash] URI [URI ...]>>>
  220. Delete files specified as args. Only deletes non empty directory and files.
  221. If the -skipTrash option is specified, the trash, if enabled, will be
  222. bypassed and the specified file(s) deleted immediately. This can be useful
  223. when it is necessary to delete files from an over-quota directory. Refer to
  224. rmr for recursive deletes.
  225. Example:
  226. * <<<hdfs dfs -rm hdfs://nn.example.com/file /user/hadoop/emptydir>>>
  227. Exit Code:
  228. Returns 0 on success and -1 on error.
  229. rmr
  230. Usage: <<<hdfs dfs -rmr [-skipTrash] URI [URI ...]>>>
  231. Recursive version of delete. If the -skipTrash option is specified, the
  232. trash, if enabled, will be bypassed and the specified file(s) deleted
  233. immediately. This can be useful when it is necessary to delete files from an
  234. over-quota directory.
  235. Example:
  236. * <<<hdfs dfs -rmr /user/hadoop/dir>>>
  237. * <<<hdfs dfs -rmr hdfs://nn.example.com/user/hadoop/dir>>>
  238. Exit Code:
  239. Returns 0 on success and -1 on error.
  240. setfacl
  241. Usage: <<<hdfs dfs -setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>] >>>
  242. Sets Access Control Lists (ACLs) of files and directories.
  243. Options:
  244. * -b: Remove all but the base ACL entries. The entries for user, group and
  245. others are retained for compatibility with permission bits.
  246. * -k: Remove the default ACL.
  247. * -R: Apply operations to all files and directories recursively.
  248. * -m: Modify ACL. New entries are added to the ACL, and existing entries
  249. are retained.
  250. * -x: Remove specified ACL entries. Other ACL entries are retained.
  251. * --set: Fully replace the ACL, discarding all existing entries. The
  252. <acl_spec> must include entries for user, group, and others for
  253. compatibility with permission bits.
  254. * <acl_spec>: Comma separated list of ACL entries.
  255. * <path>: File or directory to modify.
  256. Examples:
  257. * <<<hdfs dfs -setfacl -m user:hadoop:rw- /file>>>
  258. * <<<hdfs dfs -setfacl -x user:hadoop /file>>>
  259. * <<<hdfs dfs -setfacl -b /file>>>
  260. * <<<hdfs dfs -setfacl -k /dir>>>
  261. * <<<hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file>>>
  262. * <<<hdfs dfs -setfacl -R -m user:hadoop:r-x /dir>>>
  263. * <<<hdfs dfs -setfacl -m default:user:hadoop:r-x /dir>>>
  264. Exit Code:
  265. Returns 0 on success and non-zero on error.
  266. setrep
  267. Usage: <<<hdfs dfs -setrep [-R] [-w] <numReplicas> <path> >>>
  268. Changes the replication factor of a file. If <path> is a directory then
  269. the command recursively changes the replication factor of all files under
  270. the directory tree rooted at <path>.
  271. Options:
  272. * The -w flag requests that the command wait for the replication
  273. to complete. This can potentially take a very long time.
  274. * The -R flag is accepted for backwards compatibility. It has no effect.
  275. Example:
  276. * <<<hdfs dfs -setrep -w 3 /user/hadoop/dir1>>>
  277. Exit Code:
  278. Returns 0 on success and -1 on error.
  279. stat
  280. Usage: <<<hdfs dfs -stat URI [URI ...]>>>
  281. Returns the stat information on the path.
  282. Example:
  283. * <<<hdfs dfs -stat path>>>
  284. Exit Code:
  285. Returns 0 on success and -1 on error.
  286. tail
  287. Usage: <<<hdfs dfs -tail [-f] URI>>>
  288. Displays last kilobyte of the file to stdout.
  289. Options:
  290. * The -f option will output appended data as the file grows, as in Unix.
  291. Example:
  292. * <<<hdfs dfs -tail pathname>>>
  293. Exit Code:
  294. Returns 0 on success and -1 on error.
  295. test
  296. Usage: <<<hdfs dfs -test -[ezd] URI>>>
  297. Options:
  298. * The -e option will check to see if the file exists, returning 0 if true.
  299. * The -z option will check to see if the file is zero length, returning 0 if true.
  300. * The -d option will check to see if the path is directory, returning 0 if true.
  301. Example:
  302. * <<<hdfs dfs -test -e filename>>>
  303. text
  304. Usage: <<<hdfs dfs -text <src> >>>
  305. Takes a source file and outputs the file in text format. The allowed formats
  306. are zip and TextRecordInputStream.
  307. touchz
  308. Usage: <<<hdfs dfs -touchz URI [URI ...]>>>
  309. Create a file of zero length.
  310. Example:
  311. * <<<hadoop -touchz pathname>>>
  312. Exit Code:
  313. Returns 0 on success and -1 on error.