FileSystemShell.apt.vm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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] [-h] <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. The -h option shows sizes in human readable format.
  99. Example:
  100. * <<<hdfs dfs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2>>>
  101. * <<<hdfs dfs -count -q hdfs://nn1.example.com/file1>>>
  102. * <<<hdfs dfs -count -q -h hdfs://nn1.example.com/file1>>>
  103. Exit Code:
  104. Returns 0 on success and -1 on error.
  105. cp
  106. Usage: <<<hdfs dfs -cp [-f] [-p | -p[topax]] URI [URI ...] <dest> >>>
  107. Copy files from source to destination. This command allows multiple sources
  108. as well in which case the destination must be a directory.
  109. 'raw.*' namespace extended attributes are preserved if (1) the source and
  110. destination filesystems support them (HDFS only), and (2) all source and
  111. destination pathnames are in the /.reserved/raw hierarchy. Determination of
  112. whether raw.* namespace xattrs are preserved is independent of the
  113. -p (preserve) flag.
  114. Options:
  115. * The -f option will overwrite the destination if it already exists.
  116. * The -p option will preserve file attributes [topx] (timestamps,
  117. ownership, permission, ACL, XAttr). If -p is specified with no <arg>,
  118. then preserves timestamps, ownership, permission. If -pa is specified,
  119. then preserves permission also because ACL is a super-set of
  120. permission. Determination of whether raw namespace extended attributes
  121. are preserved is independent of the -p flag.
  122. Example:
  123. * <<<hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2>>>
  124. * <<<hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir>>>
  125. Exit Code:
  126. Returns 0 on success and -1 on error.
  127. du
  128. Usage: <<<hdfs dfs -du [-s] [-h] URI [URI ...]>>>
  129. Displays sizes of files and directories contained in the given directory or
  130. the length of a file in case its just a file.
  131. Options:
  132. * The -s option will result in an aggregate summary of file lengths being
  133. displayed, rather than the individual files.
  134. * The -h option will format file sizes in a "human-readable" fashion (e.g
  135. 64.0m instead of 67108864)
  136. Example:
  137. * hdfs dfs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1
  138. Exit Code:
  139. Returns 0 on success and -1 on error.
  140. dus
  141. Usage: <<<hdfs dfs -dus <args> >>>
  142. Displays a summary of file lengths.
  143. <<Note:>> This command is deprecated. Instead use <<<hdfs dfs -du -s>>>.
  144. expunge
  145. Usage: <<<hdfs dfs -expunge>>>
  146. Empty the Trash. Refer to the {{{../hadoop-hdfs/HdfsDesign.html}
  147. HDFS Architecture Guide}} for more information on the Trash feature.
  148. get
  149. Usage: <<<hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst> >>>
  150. Copy files to the local file system. Files that fail the CRC check may be
  151. copied with the -ignorecrc option. Files and CRCs may be copied using the
  152. -crc option.
  153. Example:
  154. * <<<hdfs dfs -get /user/hadoop/file localfile>>>
  155. * <<<hdfs dfs -get hdfs://nn.example.com/user/hadoop/file localfile>>>
  156. Exit Code:
  157. Returns 0 on success and -1 on error.
  158. getfacl
  159. Usage: <<<hdfs dfs -getfacl [-R] <path> >>>
  160. Displays the Access Control Lists (ACLs) of files and directories. If a
  161. directory has a default ACL, then getfacl also displays the default ACL.
  162. Options:
  163. * -R: List the ACLs of all files and directories recursively.
  164. * <path>: File or directory to list.
  165. Examples:
  166. * <<<hdfs dfs -getfacl /file>>>
  167. * <<<hdfs dfs -getfacl -R /dir>>>
  168. Exit Code:
  169. Returns 0 on success and non-zero on error.
  170. getfattr
  171. Usage: <<<hdfs dfs -getfattr [-R] {-n name | -d} [-e en] <path> >>>
  172. Displays the extended attribute names and values (if any) for a file or
  173. directory.
  174. Options:
  175. * -R: Recursively list the attributes for all files and directories.
  176. * -n name: Dump the named extended attribute value.
  177. * -d: Dump all extended attribute values associated with pathname.
  178. * -e <encoding>: Encode values after retrieving them. Valid encodings are "text", "hex", and "base64". Values encoded as text strings are enclosed in double quotes ("), and values encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively.
  179. * <path>: The file or directory.
  180. Examples:
  181. * <<<hdfs dfs -getfattr -d /file>>>
  182. * <<<hdfs dfs -getfattr -R -n user.myAttr /dir>>>
  183. Exit Code:
  184. Returns 0 on success and non-zero on error.
  185. getmerge
  186. Usage: <<<hdfs dfs -getmerge <src> <localdst> [addnl]>>>
  187. Takes a source directory and a destination file as input and concatenates
  188. files in src into the destination local file. Optionally addnl can be set to
  189. enable adding a newline character at the
  190. end of each file.
  191. ls
  192. Usage: <<<hdfs dfs -ls [-R] <args> >>>
  193. Options:
  194. * The -R option will return stat recursively through the directory
  195. structure.
  196. For a file returns stat on the file with the following format:
  197. +---+
  198. permissions number_of_replicas userid groupid filesize modification_date modification_time filename
  199. +---+
  200. For a directory it returns list of its direct children as in Unix. A directory is listed as:
  201. +---+
  202. permissions userid groupid modification_date modification_time dirname
  203. +---+
  204. Example:
  205. * <<<hdfs dfs -ls /user/hadoop/file1>>>
  206. Exit Code:
  207. Returns 0 on success and -1 on error.
  208. lsr
  209. Usage: <<<hdfs dfs -lsr <args> >>>
  210. Recursive version of ls.
  211. <<Note:>> This command is deprecated. Instead use <<<hdfs dfs -ls -R>>>
  212. mkdir
  213. Usage: <<<hdfs dfs -mkdir [-p] <paths> >>>
  214. Takes path uri's as argument and creates directories.
  215. Options:
  216. * The -p option behavior is much like Unix mkdir -p, creating parent directories along the path.
  217. Example:
  218. * <<<hdfs dfs -mkdir /user/hadoop/dir1 /user/hadoop/dir2>>>
  219. * <<<hdfs dfs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir>>>
  220. Exit Code:
  221. Returns 0 on success and -1 on error.
  222. moveFromLocal
  223. Usage: <<<hdfs dfs -moveFromLocal <localsrc> <dst> >>>
  224. Similar to put command, except that the source localsrc is deleted after
  225. it's copied.
  226. moveToLocal
  227. Usage: <<<hdfs dfs -moveToLocal [-crc] <src> <dst> >>>
  228. Displays a "Not implemented yet" message.
  229. mv
  230. Usage: <<<hdfs dfs -mv URI [URI ...] <dest> >>>
  231. Moves files from source to destination. This command allows multiple sources
  232. as well in which case the destination needs to be a directory. Moving files
  233. across file systems is not permitted.
  234. Example:
  235. * <<<hdfs dfs -mv /user/hadoop/file1 /user/hadoop/file2>>>
  236. * <<<hdfs dfs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/file3 hdfs://nn.example.com/dir1>>>
  237. Exit Code:
  238. Returns 0 on success and -1 on error.
  239. put
  240. Usage: <<<hdfs dfs -put <localsrc> ... <dst> >>>
  241. Copy single src, or multiple srcs from local file system to the destination
  242. file system. Also reads input from stdin and writes to destination file
  243. system.
  244. * <<<hdfs dfs -put localfile /user/hadoop/hadoopfile>>>
  245. * <<<hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir>>>
  246. * <<<hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile>>>
  247. * <<<hdfs dfs -put - hdfs://nn.example.com/hadoop/hadoopfile>>>
  248. Reads the input from stdin.
  249. Exit Code:
  250. Returns 0 on success and -1 on error.
  251. rm
  252. Usage: <<<hdfs dfs -rm [-f] [-r|-R] [-skipTrash] URI [URI ...]>>>
  253. Delete files specified as args.
  254. Options:
  255. * The -f option will not display a diagnostic message or modify the exit
  256. status to reflect an error if the file does not exist.
  257. * The -R option deletes the directory and any content under it recursively.
  258. * The -r option is equivalent to -R.
  259. * The -skipTrash option will bypass trash, if enabled, and delete the
  260. specified file(s) immediately. This can be useful when it is necessary
  261. to delete files from an over-quota directory.
  262. Example:
  263. * <<<hdfs dfs -rm hdfs://nn.example.com/file /user/hadoop/emptydir>>>
  264. Exit Code:
  265. Returns 0 on success and -1 on error.
  266. rmr
  267. Usage: <<<hdfs dfs -rmr [-skipTrash] URI [URI ...]>>>
  268. Recursive version of delete.
  269. <<Note:>> This command is deprecated. Instead use <<<hdfs dfs -rm -r>>>
  270. setfacl
  271. Usage: <<<hdfs dfs -setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>] >>>
  272. Sets Access Control Lists (ACLs) of files and directories.
  273. Options:
  274. * -b: Remove all but the base ACL entries. The entries for user, group and
  275. others are retained for compatibility with permission bits.
  276. * -k: Remove the default ACL.
  277. * -R: Apply operations to all files and directories recursively.
  278. * -m: Modify ACL. New entries are added to the ACL, and existing entries
  279. are retained.
  280. * -x: Remove specified ACL entries. Other ACL entries are retained.
  281. * --set: Fully replace the ACL, discarding all existing entries. The
  282. <acl_spec> must include entries for user, group, and others for
  283. compatibility with permission bits.
  284. * <acl_spec>: Comma separated list of ACL entries.
  285. * <path>: File or directory to modify.
  286. Examples:
  287. * <<<hdfs dfs -setfacl -m user:hadoop:rw- /file>>>
  288. * <<<hdfs dfs -setfacl -x user:hadoop /file>>>
  289. * <<<hdfs dfs -setfacl -b /file>>>
  290. * <<<hdfs dfs -setfacl -k /dir>>>
  291. * <<<hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file>>>
  292. * <<<hdfs dfs -setfacl -R -m user:hadoop:r-x /dir>>>
  293. * <<<hdfs dfs -setfacl -m default:user:hadoop:r-x /dir>>>
  294. Exit Code:
  295. Returns 0 on success and non-zero on error.
  296. setfattr
  297. Usage: <<<hdfs dfs -setfattr {-n name [-v value] | -x name} <path> >>>
  298. Sets an extended attribute name and value for a file or directory.
  299. Options:
  300. * -b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
  301. * -n name: The extended attribute name.
  302. * -v value: The extended attribute value. There are three different encoding methods for the value. If the argument is enclosed in double quotes, then the value is the string inside the quotes. If the argument is prefixed with 0x or 0X, then it is taken as a hexadecimal number. If the argument begins with 0s or 0S, then it is taken as a base64 encoding.
  303. * -x name: Remove the extended attribute.
  304. * <path>: The file or directory.
  305. Examples:
  306. * <<<hdfs dfs -setfattr -n user.myAttr -v myValue /file>>>
  307. * <<<hdfs dfs -setfattr -n user.noValue /file>>>
  308. * <<<hdfs dfs -setfattr -x user.myAttr /file>>>
  309. Exit Code:
  310. Returns 0 on success and non-zero on error.
  311. setrep
  312. Usage: <<<hdfs dfs -setrep [-R] [-w] <numReplicas> <path> >>>
  313. Changes the replication factor of a file. If <path> is a directory then
  314. the command recursively changes the replication factor of all files under
  315. the directory tree rooted at <path>.
  316. Options:
  317. * The -w flag requests that the command wait for the replication
  318. to complete. This can potentially take a very long time.
  319. * The -R flag is accepted for backwards compatibility. It has no effect.
  320. Example:
  321. * <<<hdfs dfs -setrep -w 3 /user/hadoop/dir1>>>
  322. Exit Code:
  323. Returns 0 on success and -1 on error.
  324. stat
  325. Usage: <<<hdfs dfs -stat [format] \<path\> ...>>>
  326. Print statistics about the file/directory at \<path\> in the specified
  327. format. Format accepts filesize in blocks (%b), type (%F), group name of
  328. owner (%g), name (%n), block size (%o), replication (%r), user name of
  329. owner(%u), and modification date (%y, %Y). %y shows UTC date as
  330. "yyyy-MM-dd HH:mm:ss" and %Y shows milliseconds since January 1, 1970 UTC.
  331. If the format is not specified, %y is used by default.
  332. Example:
  333. * <<<hdfs dfs -stat "%F %u:%g %b %y %n" /file>>>
  334. Exit Code:
  335. Returns 0 on success and -1 on error.
  336. tail
  337. Usage: <<<hdfs dfs -tail [-f] URI>>>
  338. Displays last kilobyte of the file to stdout.
  339. Options:
  340. * The -f option will output appended data as the file grows, as in Unix.
  341. Example:
  342. * <<<hdfs dfs -tail pathname>>>
  343. Exit Code:
  344. Returns 0 on success and -1 on error.
  345. test
  346. Usage: <<<hdfs dfs -test -[ezd] URI>>>
  347. Options:
  348. * The -e option will check to see if the file exists, returning 0 if true.
  349. * The -z option will check to see if the file is zero length, returning 0 if true.
  350. * The -d option will check to see if the path is directory, returning 0 if true.
  351. Example:
  352. * <<<hdfs dfs -test -e filename>>>
  353. text
  354. Usage: <<<hdfs dfs -text <src> >>>
  355. Takes a source file and outputs the file in text format. The allowed formats
  356. are zip and TextRecordInputStream.
  357. touchz
  358. Usage: <<<hdfs dfs -touchz URI [URI ...]>>>
  359. Create a file of zero length.
  360. Example:
  361. * <<<hdfs dfs -touchz pathname>>>
  362. Exit Code:
  363. Returns 0 on success and -1 on error.