FileSystemShell.apt.vm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. This is an alternate form of hdfs dfs -du -s.
  143. expunge
  144. Usage: <<<hdfs dfs -expunge>>>
  145. Empty the Trash. Refer to the {{{../hadoop-hdfs/HdfsDesign.html}
  146. HDFS Architecture Guide}} for more information on the Trash feature.
  147. get
  148. Usage: <<<hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst> >>>
  149. Copy files to the local file system. Files that fail the CRC check may be
  150. copied with the -ignorecrc option. Files and CRCs may be copied using the
  151. -crc option.
  152. Example:
  153. * <<<hdfs dfs -get /user/hadoop/file localfile>>>
  154. * <<<hdfs dfs -get hdfs://nn.example.com/user/hadoop/file localfile>>>
  155. Exit Code:
  156. Returns 0 on success and -1 on error.
  157. getfacl
  158. Usage: <<<hdfs dfs -getfacl [-R] <path> >>>
  159. Displays the Access Control Lists (ACLs) of files and directories. If a
  160. directory has a default ACL, then getfacl also displays the default ACL.
  161. Options:
  162. * -R: List the ACLs of all files and directories recursively.
  163. * <path>: File or directory to list.
  164. Examples:
  165. * <<<hdfs dfs -getfacl /file>>>
  166. * <<<hdfs dfs -getfacl -R /dir>>>
  167. Exit Code:
  168. Returns 0 on success and non-zero on error.
  169. getfattr
  170. Usage: <<<hdfs dfs -getfattr [-R] {-n name | -d} [-e en] <path> >>>
  171. Displays the extended attribute names and values (if any) for a file or
  172. directory.
  173. Options:
  174. * -R: Recursively list the attributes for all files and directories.
  175. * -n name: Dump the named extended attribute value.
  176. * -d: Dump all extended attribute values associated with pathname.
  177. * -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.
  178. * <path>: The file or directory.
  179. Examples:
  180. * <<<hdfs dfs -getfattr -d /file>>>
  181. * <<<hdfs dfs -getfattr -R -n user.myAttr /dir>>>
  182. Exit Code:
  183. Returns 0 on success and non-zero on error.
  184. getmerge
  185. Usage: <<<hdfs dfs -getmerge <src> <localdst> [addnl]>>>
  186. Takes a source directory and a destination file as input and concatenates
  187. files in src into the destination local file. Optionally addnl can be set to
  188. enable adding a newline character at the
  189. end of each file.
  190. ls
  191. Usage: <<<hdfs dfs -ls <args> >>>
  192. For a file returns stat on the file with the following format:
  193. +---+
  194. permissions number_of_replicas userid groupid filesize modification_date modification_time filename
  195. +---+
  196. For a directory it returns list of its direct children as in Unix. A directory is listed as:
  197. +---+
  198. permissions userid groupid modification_date modification_time dirname
  199. +---+
  200. Example:
  201. * <<<hdfs dfs -ls /user/hadoop/file1>>>
  202. Exit Code:
  203. Returns 0 on success and -1 on error.
  204. lsr
  205. Usage: <<<hdfs dfs -lsr <args> >>>
  206. Recursive version of ls. Similar to Unix ls -R.
  207. mkdir
  208. Usage: <<<hdfs dfs -mkdir [-p] <paths> >>>
  209. Takes path uri's as argument and creates directories.
  210. Options:
  211. * The -p option behavior is much like Unix mkdir -p, creating parent directories along the path.
  212. Example:
  213. * <<<hdfs dfs -mkdir /user/hadoop/dir1 /user/hadoop/dir2>>>
  214. * <<<hdfs dfs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir>>>
  215. Exit Code:
  216. Returns 0 on success and -1 on error.
  217. moveFromLocal
  218. Usage: <<<dfs -moveFromLocal <localsrc> <dst> >>>
  219. Similar to put command, except that the source localsrc is deleted after
  220. it's copied.
  221. moveToLocal
  222. Usage: <<<hdfs dfs -moveToLocal [-crc] <src> <dst> >>>
  223. Displays a "Not implemented yet" message.
  224. mv
  225. Usage: <<<hdfs dfs -mv URI [URI ...] <dest> >>>
  226. Moves files from source to destination. This command allows multiple sources
  227. as well in which case the destination needs to be a directory. Moving files
  228. across file systems is not permitted.
  229. Example:
  230. * <<<hdfs dfs -mv /user/hadoop/file1 /user/hadoop/file2>>>
  231. * <<<hdfs dfs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/file3 hdfs://nn.example.com/dir1>>>
  232. Exit Code:
  233. Returns 0 on success and -1 on error.
  234. put
  235. Usage: <<<hdfs dfs -put <localsrc> ... <dst> >>>
  236. Copy single src, or multiple srcs from local file system to the destination
  237. file system. Also reads input from stdin and writes to destination file
  238. system.
  239. * <<<hdfs dfs -put localfile /user/hadoop/hadoopfile>>>
  240. * <<<hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir>>>
  241. * <<<hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile>>>
  242. * <<<hdfs dfs -put - hdfs://nn.example.com/hadoop/hadoopfile>>>
  243. Reads the input from stdin.
  244. Exit Code:
  245. Returns 0 on success and -1 on error.
  246. rm
  247. Usage: <<<hdfs dfs -rm [-skipTrash] URI [URI ...]>>>
  248. Delete files specified as args. Only deletes non empty directory and files.
  249. If the -skipTrash option is specified, the trash, if enabled, will be
  250. bypassed and the specified file(s) deleted immediately. This can be useful
  251. when it is necessary to delete files from an over-quota directory. Refer to
  252. rmr for recursive deletes.
  253. Example:
  254. * <<<hdfs dfs -rm hdfs://nn.example.com/file /user/hadoop/emptydir>>>
  255. Exit Code:
  256. Returns 0 on success and -1 on error.
  257. rmr
  258. Usage: <<<hdfs dfs -rmr [-skipTrash] URI [URI ...]>>>
  259. Recursive version of delete. If the -skipTrash option is specified, the
  260. trash, if enabled, will be bypassed and the specified file(s) deleted
  261. immediately. This can be useful when it is necessary to delete files from an
  262. over-quota directory.
  263. Example:
  264. * <<<hdfs dfs -rmr /user/hadoop/dir>>>
  265. * <<<hdfs dfs -rmr hdfs://nn.example.com/user/hadoop/dir>>>
  266. Exit Code:
  267. Returns 0 on success and -1 on error.
  268. setfacl
  269. Usage: <<<hdfs dfs -setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>] >>>
  270. Sets Access Control Lists (ACLs) of files and directories.
  271. Options:
  272. * -b: Remove all but the base ACL entries. The entries for user, group and
  273. others are retained for compatibility with permission bits.
  274. * -k: Remove the default ACL.
  275. * -R: Apply operations to all files and directories recursively.
  276. * -m: Modify ACL. New entries are added to the ACL, and existing entries
  277. are retained.
  278. * -x: Remove specified ACL entries. Other ACL entries are retained.
  279. * --set: Fully replace the ACL, discarding all existing entries. The
  280. <acl_spec> must include entries for user, group, and others for
  281. compatibility with permission bits.
  282. * <acl_spec>: Comma separated list of ACL entries.
  283. * <path>: File or directory to modify.
  284. Examples:
  285. * <<<hdfs dfs -setfacl -m user:hadoop:rw- /file>>>
  286. * <<<hdfs dfs -setfacl -x user:hadoop /file>>>
  287. * <<<hdfs dfs -setfacl -b /file>>>
  288. * <<<hdfs dfs -setfacl -k /dir>>>
  289. * <<<hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file>>>
  290. * <<<hdfs dfs -setfacl -R -m user:hadoop:r-x /dir>>>
  291. * <<<hdfs dfs -setfacl -m default:user:hadoop:r-x /dir>>>
  292. Exit Code:
  293. Returns 0 on success and non-zero on error.
  294. setfattr
  295. Usage: <<<hdfs dfs -setfattr {-n name [-v value] | -x name} <path> >>>
  296. Sets an extended attribute name and value for a file or directory.
  297. Options:
  298. * -b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
  299. * -n name: The extended attribute name.
  300. * -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.
  301. * -x name: Remove the extended attribute.
  302. * <path>: The file or directory.
  303. Examples:
  304. * <<<hdfs dfs -setfattr -n user.myAttr -v myValue /file>>>
  305. * <<<hdfs dfs -setfattr -n user.noValue /file>>>
  306. * <<<hdfs dfs -setfattr -x user.myAttr /file>>>
  307. Exit Code:
  308. Returns 0 on success and non-zero on error.
  309. setrep
  310. Usage: <<<hdfs dfs -setrep [-R] [-w] <numReplicas> <path> >>>
  311. Changes the replication factor of a file. If <path> is a directory then
  312. the command recursively changes the replication factor of all files under
  313. the directory tree rooted at <path>.
  314. Options:
  315. * The -w flag requests that the command wait for the replication
  316. to complete. This can potentially take a very long time.
  317. * The -R flag is accepted for backwards compatibility. It has no effect.
  318. Example:
  319. * <<<hdfs dfs -setrep -w 3 /user/hadoop/dir1>>>
  320. Exit Code:
  321. Returns 0 on success and -1 on error.
  322. stat
  323. Usage: <<<hdfs dfs -stat URI [URI ...]>>>
  324. Returns the stat information on the path.
  325. Example:
  326. * <<<hdfs dfs -stat path>>>
  327. Exit Code:
  328. Returns 0 on success and -1 on error.
  329. tail
  330. Usage: <<<hdfs dfs -tail [-f] URI>>>
  331. Displays last kilobyte of the file to stdout.
  332. Options:
  333. * The -f option will output appended data as the file grows, as in Unix.
  334. Example:
  335. * <<<hdfs dfs -tail pathname>>>
  336. Exit Code:
  337. Returns 0 on success and -1 on error.
  338. test
  339. Usage: <<<hdfs dfs -test -[ezd] URI>>>
  340. Options:
  341. * The -e option will check to see if the file exists, returning 0 if true.
  342. * The -z option will check to see if the file is zero length, returning 0 if true.
  343. * The -d option will check to see if the path is directory, returning 0 if true.
  344. Example:
  345. * <<<hdfs dfs -test -e filename>>>
  346. text
  347. Usage: <<<hdfs dfs -text <src> >>>
  348. Takes a source file and outputs the file in text format. The allowed formats
  349. are zip and TextRecordInputStream.
  350. touchz
  351. Usage: <<<hdfs dfs -touchz URI [URI ...]>>>
  352. Create a file of zero length.
  353. Example:
  354. * <<<hadoop -touchz pathname>>>
  355. Exit Code:
  356. Returns 0 on success and -1 on error.