bsdcpio.1 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. .\" Copyright (c) 2003-2007 Tim Kientzle
  2. .\" All rights reserved.
  3. .\"
  4. .\" Redistribution and use in source and binary forms, with or without
  5. .\" modification, are permitted provided that the following conditions
  6. .\" are met:
  7. .\" 1. Redistributions of source code must retain the above copyright
  8. .\" notice, this list of conditions and the following disclaimer.
  9. .\" 2. Redistributions in binary form must reproduce the above copyright
  10. .\" notice, this list of conditions and the following disclaimer in the
  11. .\" documentation and/or other materials provided with the distribution.
  12. .\"
  13. .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23. .\" SUCH DAMAGE.
  24. .\"
  25. .\" $FreeBSD$
  26. .\"
  27. .Dd September 16, 2014
  28. .Dt CPIO 1
  29. .Os
  30. .Sh NAME
  31. .Nm cpio
  32. .Nd copy files to and from archives
  33. .Sh SYNOPSIS
  34. .Nm
  35. .Fl i
  36. .Op Ar options
  37. .Op Ar pattern ...
  38. .Op Ar < archive
  39. .Nm
  40. .Fl o
  41. .Op Ar options
  42. .Ar < name-list
  43. .Op Ar > archive
  44. .Nm
  45. .Fl p
  46. .Op Ar options
  47. .Ar dest-dir
  48. .Ar < name-list
  49. .Sh DESCRIPTION
  50. .Nm
  51. copies files between archives and directories.
  52. This implementation can extract from tar, pax, cpio, zip, jar, ar,
  53. and ISO 9660 cdrom images and can create tar, pax, cpio, ar,
  54. and shar archives.
  55. .Pp
  56. The first option to
  57. .Nm
  58. is a mode indicator from the following list:
  59. .Bl -tag -compact -width indent
  60. .It Fl i
  61. Input.
  62. Read an archive from standard input (unless overridden) and extract the
  63. contents to disk or (if the
  64. .Fl t
  65. option is specified)
  66. list the contents to standard output.
  67. If one or more file patterns are specified, only files matching
  68. one of the patterns will be extracted.
  69. .It Fl o
  70. Output.
  71. Read a list of filenames from standard input and produce a new archive
  72. on standard output (unless overridden) containing the specified items.
  73. .It Fl p
  74. Pass-through.
  75. Read a list of filenames from standard input and copy the files to the
  76. specified directory.
  77. .El
  78. .Sh OPTIONS
  79. Unless specifically stated otherwise, options are applicable in
  80. all operating modes.
  81. .Bl -tag -width indent
  82. .It Fl 0 , Fl Fl null
  83. Read filenames separated by NUL characters instead of newlines.
  84. This is necessary if any of the filenames being read might contain newlines.
  85. .It Fl 6 , Fl Fl pwb
  86. When reading a binary format archive, assume it's the earlier one,
  87. from the PWB variant of 6th Edition UNIX.
  88. When writing a cpio archive, use the PWB format.
  89. .It Fl 7 , Fl Fl binary
  90. (o mode only)
  91. When writing a cpio archive, use the (newer, non-PWB) binary format.
  92. .It Fl A
  93. (o mode only)
  94. Append to the specified archive.
  95. (Not yet implemented.)
  96. .It Fl a
  97. (o and p modes)
  98. Reset access times on files after they are read.
  99. .It Fl B
  100. (o mode only)
  101. Block output to records of 5120 bytes.
  102. .It Fl C Ar size
  103. (o mode only)
  104. Block output to records of
  105. .Ar size
  106. bytes.
  107. .It Fl c
  108. (o mode only)
  109. Use the old POSIX portable character format.
  110. Equivalent to
  111. .Fl Fl format Ar odc .
  112. .It Fl d , Fl Fl make-directories
  113. (i and p modes)
  114. Create directories as necessary.
  115. .It Fl E Ar file
  116. (i mode only)
  117. Read list of file name patterns from
  118. .Ar file
  119. to list and extract.
  120. .It Fl F Ar file , Fl Fl file Ar file
  121. Read archive from or write archive to
  122. .Ar file .
  123. .It Fl f Ar pattern
  124. (i mode only)
  125. Ignore files that match
  126. .Ar pattern .
  127. .It Fl H Ar format , Fl Fl format Ar format
  128. (o mode only)
  129. Produce the output archive in the specified format.
  130. Supported formats include:
  131. .Pp
  132. .Bl -tag -width "iso9660" -compact
  133. .It Ar cpio
  134. Synonym for
  135. .Ar odc .
  136. .It Ar newc
  137. The SVR4 portable cpio format.
  138. .It Ar odc
  139. The old POSIX.1 portable octet-oriented cpio format.
  140. .It Ar pax
  141. The POSIX.1 pax format, an extension of the ustar format.
  142. .It Ar ustar
  143. The POSIX.1 tar format.
  144. .El
  145. .Pp
  146. The default format is
  147. .Ar odc .
  148. See
  149. .Xr libarchive-formats 5
  150. for more complete information about the
  151. formats currently supported by the underlying
  152. .Xr libarchive 3
  153. library.
  154. .It Fl h , Fl Fl help
  155. Print usage information.
  156. .It Fl I Ar file
  157. Read archive from
  158. .Ar file .
  159. .It Fl i , Fl Fl extract
  160. Input mode.
  161. See above for description.
  162. .It Fl Fl insecure
  163. (i and p mode only)
  164. Disable security checks during extraction or copying.
  165. This allows extraction via symbolic links, absolute paths,
  166. and path names containing
  167. .Sq ..
  168. in the name.
  169. .It Fl J , Fl Fl xz
  170. (o mode only)
  171. Compress the file with xz-compatible compression before writing it.
  172. In input mode, this option is ignored; xz compression is recognized
  173. automatically on input.
  174. .It Fl j
  175. Synonym for
  176. .Fl y .
  177. .It Fl L
  178. (o and p modes)
  179. All symbolic links will be followed.
  180. Normally, symbolic links are archived and copied as symbolic links.
  181. With this option, the target of the link will be archived or copied instead.
  182. .It Fl l , Fl Fl link
  183. (p mode only)
  184. Create links from the target directory to the original files,
  185. instead of copying.
  186. .It Fl Fl lrzip
  187. (o mode only)
  188. Compress the resulting archive with
  189. .Xr lrzip 1 .
  190. In input mode, this option is ignored.
  191. .It Fl Fl lz4
  192. (o mode only)
  193. Compress the archive with lz4-compatible compression before writing it.
  194. In input mode, this option is ignored; lz4 compression is recognized
  195. automatically on input.
  196. .It Fl Fl zstd
  197. (o mode only)
  198. Compress the archive with zstd-compatible compression before writing it.
  199. In input mode, this option is ignored; zstd compression is recognized
  200. automatically on input.
  201. .It Fl Fl lzma
  202. (o mode only)
  203. Compress the file with lzma-compatible compression before writing it.
  204. In input mode, this option is ignored; lzma compression is recognized
  205. automatically on input.
  206. .It Fl Fl lzop
  207. (o mode only)
  208. Compress the resulting archive with
  209. .Xr lzop 1 .
  210. In input mode, this option is ignored.
  211. .It Fl Fl passphrase Ar passphrase
  212. The
  213. .Pa passphrase
  214. is used to extract or create an encrypted archive.
  215. Currently, zip is only a format that
  216. .Nm
  217. can handle encrypted archives.
  218. You shouldn't use this option unless you realize how insecure
  219. use of this option is.
  220. .It Fl m , Fl Fl preserve-modification-time
  221. (i and p modes)
  222. Set file modification time on created files to match
  223. those in the source.
  224. .It Fl n , Fl Fl numeric-uid-gid
  225. (i mode, only with
  226. .Fl t )
  227. Display numeric uid and gid.
  228. By default,
  229. .Nm
  230. displays the user and group names when they are provided in the
  231. archive, or looks up the user and group names in the system
  232. password database.
  233. .It Fl Fl no-preserve-owner
  234. (i mode only)
  235. Do not attempt to restore file ownership.
  236. This is the default when run by non-root users.
  237. .It Fl O Ar file
  238. Write archive to
  239. .Ar file .
  240. .It Fl o , Fl Fl create
  241. Output mode.
  242. See above for description.
  243. .It Fl p , Fl Fl pass-through
  244. Pass-through mode.
  245. See above for description.
  246. .It Fl Fl preserve-owner
  247. (i mode only)
  248. Restore file ownership.
  249. This is the default when run by the root user.
  250. .It Fl Fl quiet
  251. Suppress unnecessary messages.
  252. .It Fl R Oo user Oc Ns Oo : Oc Ns Oo group Oc , Fl Fl owner Oo user Oc Ns Oo : Oc Ns Oo group Oc
  253. Set the owner and/or group on files in the output.
  254. If group is specified with no user
  255. (for example,
  256. .Fl R Ar :wheel )
  257. then the group will be set but not the user.
  258. If the user is specified with a trailing colon and no group
  259. (for example,
  260. .Fl R Ar root: )
  261. then the group will be set to the user's default group.
  262. If the user is specified with no trailing colon, then
  263. the user will be set but not the group.
  264. In
  265. .Fl i
  266. and
  267. .Fl p
  268. modes, this option can only be used by the super-user.
  269. (For compatibility, a period can be used in place of the colon.)
  270. .It Fl r
  271. (All modes.)
  272. Rename files interactively.
  273. For each file, a prompt is written to
  274. .Pa /dev/tty
  275. containing the name of the file and a line is read from
  276. .Pa /dev/tty .
  277. If the line read is blank, the file is skipped.
  278. If the line contains a single period, the file is processed normally.
  279. Otherwise, the line is taken to be the new name of the file.
  280. .It Fl t , Fl Fl list
  281. (i mode only)
  282. List the contents of the archive to stdout;
  283. do not restore the contents to disk.
  284. .It Fl u , Fl Fl unconditional
  285. (i and p modes)
  286. Unconditionally overwrite existing files.
  287. Ordinarily, an older file will not overwrite a newer file on disk.
  288. .It Fl V , Fl Fl dot
  289. Print a dot to stderr for each file as it is processed.
  290. Superseded by
  291. .Fl v .
  292. .It Fl v , Fl Fl verbose
  293. Print the name of each file to stderr as it is processed.
  294. With
  295. .Fl t ,
  296. provide a detailed listing of each file.
  297. .It Fl Fl version
  298. Print the program version information and exit.
  299. .It Fl y
  300. (o mode only)
  301. Compress the archive with bzip2-compatible compression before writing it.
  302. In input mode, this option is ignored;
  303. bzip2 compression is recognized automatically on input.
  304. .It Fl Z
  305. (o mode only)
  306. Compress the archive with compress-compatible compression before writing it.
  307. In input mode, this option is ignored;
  308. compression is recognized automatically on input.
  309. .It Fl z
  310. (o mode only)
  311. Compress the archive with gzip-compatible compression before writing it.
  312. In input mode, this option is ignored;
  313. gzip compression is recognized automatically on input.
  314. .El
  315. .Sh EXIT STATUS
  316. .Ex -std
  317. .Sh ENVIRONMENT
  318. The following environment variables affect the execution of
  319. .Nm :
  320. .Bl -tag -width ".Ev BLOCKSIZE"
  321. .It Ev LANG
  322. The locale to use.
  323. See
  324. .Xr environ 7
  325. for more information.
  326. .It Ev TZ
  327. The timezone to use when displaying dates.
  328. See
  329. .Xr environ 7
  330. for more information.
  331. .El
  332. .Sh EXAMPLES
  333. The
  334. .Nm
  335. command is traditionally used to copy file hierarchies in conjunction
  336. with the
  337. .Xr find 1
  338. command.
  339. The first example here simply copies all files from
  340. .Pa src
  341. to
  342. .Pa dest :
  343. .Dl Nm find Pa src | Nm Fl pmud Pa dest
  344. .Pp
  345. By carefully selecting options to the
  346. .Xr find 1
  347. command and combining it with other standard utilities,
  348. it is possible to exercise very fine control over which files are copied.
  349. This next example copies files from
  350. .Pa src
  351. to
  352. .Pa dest
  353. that are more than 2 days old and whose names match a particular pattern:
  354. .Dl Nm find Pa src Fl mtime Ar +2 | Nm grep foo[bar] | Nm Fl pdmu Pa dest
  355. .Pp
  356. This example copies files from
  357. .Pa src
  358. to
  359. .Pa dest
  360. that are more than 2 days old and which contain the word
  361. .Do foobar Dc :
  362. .Dl Nm find Pa src Fl mtime Ar +2 | Nm xargs Nm grep -l foobar | Nm Fl pdmu Pa dest
  363. .Sh COMPATIBILITY
  364. The mode options i, o, and p and the options
  365. a, B, c, d, f, l, m, r, t, u, and v comply with SUSv2.
  366. .Pp
  367. The old POSIX.1 standard specified that only
  368. .Fl i ,
  369. .Fl o ,
  370. and
  371. .Fl p
  372. were interpreted as command-line options.
  373. Each took a single argument of a list of modifier
  374. characters.
  375. For example, the standard syntax allows
  376. .Fl imu
  377. but does not support
  378. .Fl miu
  379. or
  380. .Fl i Fl m Fl u ,
  381. since
  382. .Ar m
  383. and
  384. .Ar u
  385. are only modifiers to
  386. .Fl i ,
  387. they are not command-line options in their own right.
  388. The syntax supported by this implementation is backwards-compatible
  389. with the standard.
  390. For best compatibility, scripts should limit themselves to the
  391. standard syntax.
  392. .Sh SEE ALSO
  393. .Xr bzip2 1 ,
  394. .Xr gzip 1 ,
  395. .Xr mt 1 ,
  396. .Xr pax 1 ,
  397. .Xr tar 1 ,
  398. .Xr libarchive 3 ,
  399. .Xr cpio 5 ,
  400. .Xr libarchive-formats 5 ,
  401. .Xr tar 5
  402. .Sh STANDARDS
  403. There is no current POSIX standard for the cpio command; it appeared
  404. in
  405. .St -p1003.1-96
  406. but was dropped from
  407. .St -p1003.1-2001 .
  408. .Pp
  409. The cpio, ustar, and pax interchange file formats are defined by
  410. .St -p1003.1-2001
  411. for the pax command.
  412. .Sh HISTORY
  413. The original
  414. .Nm cpio
  415. and
  416. .Nm find
  417. utilities were written by Dick Haight
  418. while working in AT&T's Unix Support Group.
  419. They first appeared in 1977 in PWB/UNIX 1.0, the
  420. .Dq Programmer's Work Bench
  421. system developed for use within AT&T.
  422. They were first released outside of AT&T as part of System III Unix in 1981.
  423. As a result,
  424. .Nm cpio
  425. actually predates
  426. .Nm tar ,
  427. even though it was not well-known outside of AT&T until some time later.
  428. .Pp
  429. This is a complete re-implementation based on the
  430. .Xr libarchive 3
  431. library.
  432. .Sh BUGS
  433. The cpio archive format has several basic limitations:
  434. It does not store user and group names, only numbers.
  435. As a result, it cannot be reliably used to transfer
  436. files between systems with dissimilar user and group numbering.
  437. Older cpio formats limit the user and group numbers to
  438. 16 or 18 bits, which is insufficient for modern systems.
  439. The cpio archive formats cannot support files over 4 gigabytes,
  440. except for the
  441. .Dq odc
  442. variant, which can support files up to 8 gigabytes.