logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

tar.1 (13336B)


  1. .\" $OpenBSD: tar.1,v 1.67 2024/04/16 23:09:35 jca Exp $
  2. .\"
  3. .\" Copyright (c) 1996 SigmaSoft, Th. Lockert
  4. .\" All rights reserved.
  5. .\"
  6. .\" Redistribution and use in source and binary forms, with or without
  7. .\" modification, are permitted provided that the following conditions
  8. .\" are met:
  9. .\" 1. Redistributions of source code must retain the above copyright
  10. .\" notice, this list of conditions and the following disclaimer.
  11. .\" 2. Redistributions in binary form must reproduce the above copyright
  12. .\" notice, this list of conditions and the following disclaimer in the
  13. .\" documentation and/or other materials provided with the distribution.
  14. .\"
  15. .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. .\"
  26. .Dd $Mdocdate: April 16 2024 $
  27. .Dt TAR 1
  28. .Os
  29. .Sh NAME
  30. .Nm tar
  31. .Nd tape archiver
  32. .Sh SYNOPSIS
  33. .Nm tar
  34. .Sm off
  35. .No { Cm crtux No } Op Cm 014578beFfHhjLmNOoPpqsvwXZz
  36. .Sm on
  37. .Bk -words
  38. .Op Ar blocking-factor | format | archive | replstr
  39. .Op Fl C Ar directory
  40. .Op Fl I Ar file
  41. .Op Ar
  42. .Ek
  43. .Nm tar
  44. .No { Ns Fl crtux Ns }
  45. .Bk -words
  46. .Op Fl 014578eHhjLmNOoPpqvwXZz
  47. .Op Fl b Ar blocking-factor
  48. .Op Fl C Ar directory
  49. .Op Fl F Ar format
  50. .Op Fl f Ar archive
  51. .Op Fl I Ar file
  52. .Op Fl s Ar replstr
  53. .Op Ar
  54. .Ek
  55. .Sh DESCRIPTION
  56. The
  57. .Nm
  58. command creates, adds files to, or extracts files from an
  59. archive file in
  60. .Dq tar
  61. format.
  62. A tar archive is often stored on a magnetic tape, but can be
  63. stored equally well on a floppy, CD-ROM, or in a regular disk file.
  64. .Pp
  65. In the first (legacy) form, all option flags except for
  66. .Fl C
  67. and
  68. .Fl I
  69. must be contained within the first argument to
  70. .Nm
  71. and must not be prefixed by a hyphen
  72. .Pq Sq - .
  73. Option arguments, if any, are processed as subsequent arguments to
  74. .Nm
  75. and are processed in the order in which their corresponding option
  76. flags have been presented on the command line.
  77. .Pp
  78. In the second and preferred form, option flags may be given in any order
  79. and are immediately followed by their corresponding option argument
  80. values.
  81. .Pp
  82. One of the following flags must be present:
  83. .Bl -tag -width Ds
  84. .It Fl c
  85. Create new archive, or overwrite an existing archive,
  86. adding the specified files to it.
  87. .It Fl r
  88. Append the named new files to existing archive.
  89. Note that this will only work on media on which an end-of-file mark
  90. can be overwritten.
  91. .It Fl t
  92. List contents of archive.
  93. If any files are named on the
  94. command line, only those files will be listed.
  95. The
  96. .Ar file
  97. arguments may be specified as glob patterns (see
  98. .Xr glob 7
  99. for more information), in which case
  100. .Nm
  101. will list all archive members that match each pattern.
  102. .It Fl u
  103. Alias for
  104. .Fl r .
  105. .It Fl x
  106. Extract files from archive.
  107. If any files are named on the
  108. command line, only those files will be extracted from the
  109. archive.
  110. The
  111. .Ar file
  112. arguments may be specified as glob patterns (see
  113. .Xr glob 7
  114. for more information), in which case
  115. .Nm
  116. will extract all archive members that match each pattern.
  117. .Pp
  118. If more than one copy of a file exists in the
  119. archive, later copies will overwrite earlier copies during
  120. extraction.
  121. The file mode and modification time are preserved
  122. if possible.
  123. The file mode is subject to modification by the
  124. .Xr umask 2 .
  125. .El
  126. .Pp
  127. In addition to the flags mentioned above, any of the following
  128. flags may be used:
  129. .Bl -tag -width Ds
  130. .It Fl b Ar blocking-factor
  131. Set blocking factor to use for the archive.
  132. .Nm
  133. uses 512-byte blocks.
  134. The default is 20, the maximum is 126.
  135. Archives with a blocking factor larger than 63
  136. violate the POSIX standard and will not be portable to all systems.
  137. .It Fl C Ar directory
  138. This is a positional argument which sets the working directory for the
  139. following files.
  140. When extracting, files will be extracted into
  141. the specified directory; when creating, the specified files will be matched
  142. from the directory.
  143. .It Fl e
  144. Stop after the first error.
  145. .It Fl F Ar format
  146. Specify the output archive format, with the default format being
  147. .Cm pax .
  148. .Nm
  149. currently supports the following formats:
  150. .Bl -tag -width "sv4cpio"
  151. .It Cm bcpio
  152. The old binary cpio format.
  153. The default blocksize for this format is 5120 bytes.
  154. This format is not very portable and should not be used when other formats
  155. are available.
  156. Inode and device information about a file (used for detecting file hard links
  157. by this format), which may be truncated by this format, is detected by
  158. .Nm
  159. and is repaired.
  160. .It Cm cpio
  161. The extended cpio interchange format specified in the
  162. .St -p1003.2
  163. standard.
  164. The default blocksize for this format is 5120 bytes.
  165. Inode and device information about a file (used for detecting file hard links
  166. by this format), which may be truncated by this format, is detected by
  167. .Nm
  168. and is repaired.
  169. .It Cm sv4cpio
  170. The System V release 4 cpio.
  171. The default blocksize for this format is 5120 bytes.
  172. Inode and device information about a file (used for detecting file hard links
  173. by this format), which may be truncated by this format, is detected by
  174. .Nm
  175. and is repaired.
  176. .It Cm sv4crc
  177. The System V release 4 cpio with file CRC checksums.
  178. The default blocksize for this format is 5120 bytes.
  179. Inode and device information about a file (used for detecting file hard links
  180. by this format), which may be truncated by this format, is detected by
  181. .Nm
  182. and is repaired.
  183. .It Cm tar
  184. The old
  185. .Bx
  186. tar format as found in
  187. .Bx 4.3 .
  188. The default blocksize for this format is 10240 bytes.
  189. Pathnames stored by this format must be 100 characters or less in length.
  190. Only regular files, hard links, soft links, and directories
  191. will be archived (other file system types are not supported).
  192. For backwards compatibility with even older tar formats, see the
  193. description for
  194. .Fl o .
  195. .It Cm ustar
  196. The extended tar interchange format specified in the
  197. .St -p1003.2
  198. standard.
  199. The default blocksize for this format is 10240 bytes.
  200. Filenames stored by this format must be 100 characters or less in length;
  201. the total pathname must be 256 characters or less.
  202. .It Cm pax
  203. The pax interchange format specified in the
  204. .St -p1003.1-2001
  205. standard.
  206. The default blocksize for this format is 5120 bytes.
  207. .El
  208. .Pp
  209. .Nm
  210. will detect and report any file that it is unable to store or extract
  211. as the result of any specific archive format restrictions.
  212. The individual archive formats may impose additional restrictions on use.
  213. Typical archive format restrictions include (but are not limited to):
  214. file pathname length, file size, link pathname length, and the type of the
  215. file.
  216. .It Fl f Ar archive
  217. Read from or write to
  218. .Ar archive .
  219. A hyphen
  220. .Pq -
  221. can be used to represent standard input or output.
  222. The default is
  223. .Pa /dev/rst0 .
  224. See also the
  225. .Ev TAPE
  226. environment variable.
  227. .It Fl H
  228. Follow symlinks given on the command line only.
  229. .It Fl h
  230. Follow symbolic links as if they were normal files
  231. or directories.
  232. In extract mode this means that a directory entry in the archive
  233. will not overwrite an existing symbolic link, but rather what the
  234. link ultimately points to.
  235. .It Fl I Ar file
  236. This is a positional argument which reads the names of files to
  237. archive or extract from the given file, one per line.
  238. .It Fl j
  239. Compress archive using bzip2.
  240. The bzip2 utility must be installed separately.
  241. .It Fl L
  242. Synonym for the
  243. .Fl h
  244. option.
  245. .It Fl m
  246. Do not preserve modification time.
  247. .It Fl N
  248. Use only the numeric UID and GID values when creating or extracting an
  249. archive.
  250. .It Fl O
  251. Write old-style (non-POSIX) archives.
  252. .It Fl o
  253. Don't write directory information that the older (V7) style
  254. .Nm
  255. is unable to decode.
  256. This implies the
  257. .Fl O
  258. flag.
  259. .It Fl P
  260. Do not strip leading slashes
  261. .Pq Sq /
  262. from pathnames.
  263. The default is to strip leading slashes.
  264. .It Fl p
  265. Preserve user and group ID as well as file mode regardless of
  266. the current
  267. .Xr umask 2 .
  268. The setuid and setgid bits are only preserved if the user and group ID
  269. could be preserved.
  270. Only meaningful in conjunction with the
  271. .Fl x
  272. flag.
  273. .It Fl q
  274. Select the first archive member that matches each
  275. .Ar file
  276. operand.
  277. No more than one archive member is matched for each
  278. .Ar file .
  279. When members of type directory are matched, the file hierarchy rooted at that
  280. directory is also matched.
  281. .It Fl s Ar replstr
  282. Modify the archive member names according to the substitution expression
  283. .Ar replstr ,
  284. using the syntax of the
  285. .Xr ed 1
  286. utility regular expressions.
  287. .Ar file
  288. arguments may be given to restrict the list of archive members to those
  289. specified.
  290. .Pp
  291. The format of these regular expressions is
  292. .Pp
  293. .Dl /old/new/[gp]
  294. .Pp
  295. As in
  296. .Xr ed 1 ,
  297. .Va old
  298. is a basic regular expression (see
  299. .Xr re_format 7 )
  300. and
  301. .Va new
  302. can contain an ampersand
  303. .Pq Ql & ,
  304. .Ql \e Ns Em n
  305. (where
  306. .Em n
  307. is a digit) back-references,
  308. or subexpression matching.
  309. The
  310. .Va old
  311. string may also contain newline characters.
  312. Any non-null character can be used as a delimiter
  313. .Po
  314. .Ql /
  315. is shown here
  316. .Pc .
  317. Multiple
  318. .Fl s
  319. expressions can be specified.
  320. The expressions are applied in the order they are specified on the
  321. command line, terminating with the first successful substitution.
  322. .Pp
  323. The optional trailing
  324. .Cm g
  325. continues to apply the substitution expression to the pathname substring,
  326. which starts with the first character following the end of the last successful
  327. substitution.
  328. The first unsuccessful substitution stops the operation of the
  329. .Cm g
  330. option.
  331. The optional trailing
  332. .Cm p
  333. will cause the final result of a successful substitution to be written to
  334. standard error in the following format:
  335. .Pp
  336. .D1 Em original-pathname No >> Em new-pathname
  337. .Pp
  338. File or archive member names that substitute to the empty string
  339. are not selected and will be skipped.
  340. .It Fl v
  341. Verbose operation mode.
  342. If
  343. .Fl v
  344. is specified multiple times or if the
  345. .Fl t
  346. option is also specified,
  347. .Nm
  348. will use a long format for listing files, similar to
  349. .Xr ls 1
  350. .Fl l .
  351. .It Fl w
  352. Interactively rename files.
  353. This option causes
  354. .Nm
  355. to prompt the user for the filename to use when storing or
  356. extracting files in an archive.
  357. .It Fl X
  358. Do not cross mount points in the file system.
  359. .It Fl Z
  360. Compress archive using
  361. .Xr compress 1 .
  362. .It Fl z
  363. Compress archive using
  364. .Xr gzip 1 .
  365. .El
  366. .Pp
  367. The options
  368. .Op Fl 014578
  369. can be used to select one of the compiled-in backup devices,
  370. .Pa /dev/rstN .
  371. .Sh ENVIRONMENT
  372. .Bl -tag -width Ds
  373. .It Ev TMPDIR
  374. Path in which to store temporary files.
  375. .It Ev TAPE
  376. Default tape device to use instead of
  377. .Pa /dev/rst0 .
  378. If set to hyphen
  379. .Pq Sq - ,
  380. standard output is used.
  381. .El
  382. .Sh FILES
  383. .Bl -tag -width "/dev/rst0"
  384. .It Pa /dev/rst0
  385. default archive name
  386. .El
  387. .Sh EXIT STATUS
  388. The
  389. .Nm
  390. utility exits with one of the following values:
  391. .Pp
  392. .Bl -tag -width Ds -offset indent -compact
  393. .It 0
  394. All files were processed successfully.
  395. .It 1
  396. An error occurred.
  397. .El
  398. .Sh EXAMPLES
  399. Create an archive on the default tape drive, containing the files named
  400. .Pa bonvole
  401. and
  402. .Pa sekve :
  403. .Pp
  404. .Dl $ tar c bonvole sekve
  405. .Pp
  406. Create a
  407. .Xr gzip 1
  408. compressed archive, called
  409. .Pa foriru.tar.gz ,
  410. containing the files
  411. .Pa bonvole
  412. and
  413. .Pa sekve :
  414. .Pp
  415. .Dl $ tar czf foriru.tar.gz bonvole sekve
  416. .Pp
  417. Verbosely create an archive, called
  418. .Pa backup.tar.gz ,
  419. of all files matching the shell
  420. .Xr glob 7
  421. function
  422. .Pa *.c :
  423. .Pp
  424. .Dl $ tar cvzf backup.tar.gz *.c
  425. .Pp
  426. Verbosely list, but do not extract, all files ending in
  427. .Pa .jpeg
  428. from a compressed archive named
  429. .Pa backup.tar.gz .
  430. Note that the glob pattern has been quoted to avoid expansion by the shell:
  431. .Pp
  432. .Dl $ tar tvzf backup.tar.gz '*.jpeg'
  433. .Pp
  434. Verbosely extract an archive, called
  435. .Pa foo.tar.gz ,
  436. to the directory
  437. .Pa /var/foo :
  438. .Pp
  439. .Dl $ tar xvzf foo.tar.gz -C /var/foo
  440. .Pp
  441. For more detailed examples, see
  442. .Xr pax 1 .
  443. .Sh DIAGNOSTICS
  444. Whenever
  445. .Nm
  446. cannot create a file or a link when extracting an archive or cannot
  447. find a file while writing an archive, or cannot preserve the user
  448. ID, group ID, file mode, or access and modification times when the
  449. .Fl p
  450. option is specified, a diagnostic message is written to standard
  451. error and a non-zero exit value will be returned, but processing
  452. will continue.
  453. In the case where
  454. .Nm
  455. cannot create a link to a file,
  456. .Nm
  457. will not create a second copy of the file.
  458. .Pp
  459. If the extraction of a file from an archive is prematurely terminated
  460. by a signal or error,
  461. .Nm
  462. may have only partially extracted the file the user wanted.
  463. Additionally, the file modes of extracted files and directories may
  464. have incorrect file bits, and the modification and access times may
  465. be wrong.
  466. .Pp
  467. If the creation of an archive is prematurely terminated by a signal
  468. or error,
  469. .Nm
  470. may have only partially created the archive, which may violate the
  471. specific archive format specification.
  472. .Sh SEE ALSO
  473. .Xr cpio 1 ,
  474. .Xr pax 1
  475. .Sh HISTORY
  476. A
  477. .Nm
  478. command first appeared in
  479. .At v7 .
  480. .Sh AUTHORS
  481. .An Keith Muller
  482. at the University of California, San Diego.
  483. .Sh CAVEATS
  484. The
  485. .Fl j
  486. and
  487. .Fl L
  488. flags are not portable to other versions of
  489. .Nm
  490. where they may have a different meaning.