xref: /openbsd/bin/pax/pax.1 (revision 5dea098c)
1.\"	$OpenBSD: pax.1,v 1.79 2024/04/17 15:48:44 jca Exp $
2.\"	$NetBSD: pax.1,v 1.3 1995/03/21 09:07:37 cgd Exp $
3.\"
4.\" Copyright (c) 1992 Keith Muller.
5.\" Copyright (c) 1992, 1993
6.\"	The Regents of the University of California.  All rights reserved.
7.\"
8.\" This code is derived from software contributed to Berkeley by
9.\" Keith Muller of the University of California, San Diego.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\" 3. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"	@(#)pax.1	8.4 (Berkeley) 4/18/94
36.\"
37.Dd $Mdocdate: April 17 2024 $
38.Dt PAX 1
39.Os
40.Sh NAME
41.Nm pax
42.Nd read and write file archives and copy directory hierarchies
43.Sh SYNOPSIS
44.Nm pax
45.Op Fl 0cdjnOvz
46.Op Fl E Ar limit
47.Op Fl f Ar archive
48.Op Fl G Ar group
49.Op Fl s Ar replstr
50.Op Fl T Ar range
51.Op Fl U Ar user
52.Op Ar pattern ...
53.Nm pax
54.Fl r
55.Op Fl 0cDdijknOuvYZz
56.Op Fl E Ar limit
57.Op Fl f Ar archive
58.Op Fl G Ar group
59.Op Fl o Ar options
60.Op Fl p Ar string
61.Op Fl s Ar replstr
62.Op Fl T Ar range
63.Op Fl U Ar user
64.Op Ar pattern ...
65.Nm pax
66.Fl w
67.Op Fl 0adHijLOPtuvXz
68.Op Fl B Ar bytes
69.Op Fl b Ar blocksize
70.Op Fl f Ar archive
71.Op Fl G Ar group
72.Op Fl o Ar options
73.Op Fl s Ar replstr
74.Op Fl T Ar range
75.Op Fl U Ar user
76.Op Fl x Ar format
77.Op Ar
78.Nm pax
79.Fl rw
80.Op Fl 0DdHijkLlnOPtuvXYZ
81.Op Fl G Ar group
82.Op Fl p Ar string
83.Op Fl s Ar replstr
84.Op Fl T Ar range
85.Op Fl U Ar user
86.Op Ar
87.Ar directory
88.Sh DESCRIPTION
89.Nm
90will read, write, and list the members of an archive file
91and will copy directory hierarchies.
92.Nm
93operation is independent of the specific archive format
94and supports a wide variety of different archive formats.
95A list of supported archive formats can be found under the description of the
96.Fl x
97option.
98.Pp
99The presence of the
100.Fl r
101and the
102.Fl w
103options specifies which of the following functional modes
104.Nm
105will operate under:
106.Em list , read , write ,
107and
108.Em copy .
109.Bl -tag -width 6n
110.It Aq none
111.Em List .
112.Nm
113will write to standard output
114a table of contents of the members of the archive file read from
115standard input, whose pathnames match the specified
116.Ar pattern
117arguments.
118The table of contents contains one filename per line
119and is written using single line buffering.
120.It Fl r
121.Em Read .
122.Nm
123extracts the members of the archive file read from the standard input,
124with pathnames matching the specified
125.Ar pattern
126arguments.
127The archive format and blocking is automatically determined on input.
128When an extracted file is a directory, the entire file hierarchy
129rooted at that directory is extracted.
130All extracted files are created relative to the current file hierarchy.
131The setting of ownership, access and modification times, and file mode of
132the extracted files are discussed in more detail under the
133.Fl p
134option.
135.It Fl w
136.Em Write .
137.Nm
138writes an archive containing the
139.Ar file
140operands to standard output
141using the specified archive format.
142When no
143.Ar file
144operands are specified, a list of files to copy with one per line is read from
145standard input.
146When a
147.Ar file
148operand is also a directory, the entire file hierarchy rooted
149at that directory will be included.
150.It Fl rw
151.Em Copy .
152.Nm
153copies the
154.Ar file
155operands to the destination
156.Ar directory .
157When no
158.Ar file
159operands are specified, a list of files to copy with one per line is read from
160the standard input.
161When a
162.Ar file
163operand is also a directory, the entire file
164hierarchy rooted at that directory will be included.
165The effect of the
166.Em copy
167is as if the copied files were written to an archive file and then
168subsequently extracted, except that there may be hard links between
169the original and the copied files (see the
170.Fl l
171option below).
172.Pp
173.Sy Warning :
174The destination
175.Ar directory
176must not be one of the
177.Ar file
178operands or a member of a file hierarchy rooted at one of the
179.Ar file
180operands.
181The result of a
182.Em copy
183under these conditions is unpredictable.
184.El
185.Pp
186While processing a damaged archive during a read or list operation,
187.Nm
188will attempt to recover from media defects and will search through the archive
189to locate and process the largest number of archive members possible (see the
190.Fl E
191option for more details on error handling).
192.Pp
193The
194.Ar directory
195operand specifies a destination directory pathname.
196If the
197.Ar directory
198operand does not exist, or it is not writable by the user,
199or it is not of type directory,
200.Nm
201will exit with a non-zero exit status.
202.Pp
203The
204.Ar pattern
205operand is used to select one or more pathnames of archive members.
206Archive members are selected using the pattern matching notation described
207by
208.Xr glob 7 .
209When the
210.Ar pattern
211operand is not supplied, all members of the archive will be selected.
212When a
213.Ar pattern
214matches a directory, the entire file hierarchy rooted at that directory will
215be selected.
216When a
217.Ar pattern
218operand does not select at least one archive member,
219.Nm
220will write these
221.Ar pattern
222operands in a diagnostic message to standard error
223and then exit with a non-zero exit status.
224.Pp
225The
226.Ar file
227operand specifies the pathname of a file to be copied or archived.
228When a
229.Ar file
230operand does not select at least one archive member,
231.Nm
232will write these
233.Ar file
234operand pathnames in a diagnostic message to standard error
235and then exit with a non-zero exit status.
236.Pp
237The options are as follows:
238.Bl -tag -width Ds
239.It Fl 0
240Use the NUL
241.Pq Ql \e0
242character as a pathname terminator, instead of newline
243.Pq Ql \en .
244This applies only to the pathnames read from standard input in
245the write and copy modes,
246and to the pathnames written to standard output in list mode.
247This option is expected to be used in concert with the
248.Fl print0
249function in
250.Xr find 1
251or the
252.Fl 0
253flag in
254.Xr xargs 1 .
255.It Fl a
256Append the given
257.Ar file
258operands
259to the end of an archive that was previously written.
260If an archive format is not specified with a
261.Fl x
262option, the format currently being used in the archive will be selected.
263Any attempt to append to an archive in a format different from the
264format already used in the archive will cause
265.Nm
266to exit immediately
267with a non-zero exit status.
268The blocking size used in the archive volume where writing starts
269will continue to be used for the remainder of that archive volume.
270.Pp
271.Sy Warning :
272Many storage devices are not able to support the operations necessary
273to perform an append operation.
274Any attempt to append to an archive stored on such a device may damage the
275archive or have other unpredictable results.
276Tape drives in particular are more likely to not support an append operation.
277An archive stored in a regular file system file or on a disk device will
278usually support an append operation.
279.It Fl B Ar bytes
280Limit the number of bytes written to a single archive volume to
281.Ar bytes .
282The
283.Ar bytes
284limit can end with
285.Sq Li m ,
286.Sq Li k ,
287or
288.Sq Li b
289to specify multiplication by 1048576 (1M), 1024 (1K) or 512, respectively.
290A pair of
291.Ar bytes
292limits can be separated by
293.Sq Li x
294to indicate a product.
295.Pp
296.Sy Warning :
297Only use this option when writing an archive to a device which supports
298an end of file read condition based on last (or largest) write offset
299(such as a regular file or a tape drive).
300The use of this option with a floppy or hard disk is not recommended.
301.It Fl b Ar blocksize
302When writing an archive,
303block the output at a positive decimal integer number of
304bytes per write to the archive file.
305The
306.Ar blocksize
307must be a multiple of 512 bytes with a maximum of 64512 bytes.
308Archive block sizes larger than 32256 bytes violate the POSIX
309standard and will not be portable to all systems.
310A
311.Ar blocksize
312can end with
313.Sq Li k
314or
315.Sq Li b
316to specify multiplication by 1024 (1K) or 512, respectively.
317A pair of blocksizes can be separated by
318.Sq Li x
319to indicate a product.
320A specific archive device may impose additional restrictions on the size
321of blocking it will support.
322When blocking is not specified, the default
323.Ar blocksize
324is dependent on the specific archive format being used (see the
325.Fl x
326option).
327.It Fl c
328Match all file or archive members
329.Em except
330those specified by the
331.Ar pattern
332and
333.Ar file
334operands.
335.It Fl D
336This option is the same as the
337.Fl u
338option, except that the file inode change time is checked instead of the
339file modification time.
340The file inode change time can be used to select files whose inode information
341(e.g., UID, GID, etc.) is newer than a copy of the file in the destination
342.Ar directory .
343.It Fl d
344Cause files of type directory being copied or archived, or archive members of
345type directory being extracted, to match only the directory file or archive
346member and not the file hierarchy rooted at the directory.
347.It Fl E Ar limit
348Limit the number of consecutive read faults while trying to read a flawed
349archive to
350.Ar limit .
351With a positive
352.Ar limit ,
353.Nm
354will attempt to recover from an archive read error and will
355continue processing starting with the next file stored in the archive.
356A
357.Ar limit
358of 0 will cause
359.Nm
360to stop operation after the first read error is detected on an archive volume.
361The default
362.Ar limit
363is a small positive number of retries.
364.It Fl f Ar archive
365Specify
366.Ar archive
367as the pathname of the input or output archive, overriding the default
368standard input (for list and read)
369or standard output
370(for write).
371A single archive may span multiple files and different archive devices.
372When required,
373.Nm
374will prompt for the pathname of the file or device of the next volume in the
375archive.
376.It Fl G Ar group
377Select a file based on its
378.Ar group
379name, or when starting with a
380.Cm # ,
381a numeric GID.
382A
383.Ql \e
384can be used to escape the
385.Cm # .
386Multiple
387.Fl G
388options may be supplied and checking stops with the first match.
389.It Fl H
390Follow only command-line symbolic links while performing a physical file
391system traversal.
392.It Fl i
393Interactively rename files or archive members.
394For each archive member matching a
395.Ar pattern
396operand or each file matching a
397.Ar file
398operand,
399.Nm
400will prompt to
401.Pa /dev/tty
402giving the name of the file, its file mode, and its modification time.
403.Nm
404will then read a line from
405.Pa /dev/tty .
406If this line is blank, the file or archive member is skipped.
407If this line consists of a single period, the
408file or archive member is processed with no modification to its name.
409Otherwise, its name is replaced with the contents of the line.
410.Nm
411will immediately exit with a non-zero exit status if
412.Dv EOF
413is encountered when reading a response or if
414.Pa /dev/tty
415cannot be opened for reading and writing.
416.It Fl j
417Use bzip2 to compress (decompress) the archive while writing (reading).
418The bzip2 utility must be installed separately.
419Incompatible with
420.Fl a .
421.It Fl k
422Do not overwrite existing files.
423.It Fl L
424Follow all symbolic links to perform a logical file system traversal.
425.It Fl l
426(The lowercase letter
427.Dq ell . )
428Link files.
429In copy mode
430.Pq Fl r Fl w ,
431hard links are made between the source and destination file hierarchies
432whenever possible.
433.It Fl n
434Select the first archive member that matches each
435.Ar pattern
436operand.
437No more than one archive member is matched for each
438.Ar pattern .
439When members of type directory are matched, the file hierarchy rooted at that
440directory is also matched (unless
441.Fl d
442is also specified).
443.It Fl O
444Force the archive to be one volume.
445If a volume ends prematurely,
446.Nm
447will not prompt for a new volume.
448This option can be useful for
449automated tasks where error recovery cannot be performed by a human.
450.It Fl o Ar options
451Information to modify the algorithm for extracting or writing archive files
452which is specific to the archive format specified by
453.Fl x .
454In general,
455.Ar options
456take the form:
457.Ar name Ns = Ns Ar value .
458.Pp
459The following options are available for the
460.Cm ustar
461and old
462.Bx
463.Cm tar
464formats:
465.Pp
466.Bl -tag -width Ds -compact
467.It Cm write_opt=nodir
468When writing archives, omit the storage of directories.
469.El
470.It Fl P
471Do not follow symbolic links, perform a physical file system traversal.
472This is the default mode.
473.It Fl p Ar string
474Specify one or more file characteristic options (privileges).
475The
476.Ar string
477option-argument is a string specifying file characteristics to be retained or
478discarded on extraction.
479The string consists of the specification characters
480.Cm a , e , m , o ,
481and
482.Cm p .
483Multiple characteristics can be concatenated within the same string
484and multiple
485.Fl p
486options can be specified.
487The meanings of the specification characters are as follows:
488.Bl -tag -width 2n
489.It Cm a
490Do not preserve file access times.
491By default, file access times are preserved whenever possible.
492.It Cm e
493.Dq Preserve everything ,
494the user ID, group ID, file mode bits,
495file access time, and file modification time.
496This is intended to be used by root,
497someone with all the appropriate privileges, in order to preserve all
498aspects of the files as they are recorded in the archive.
499The
500.Cm e
501flag is the sum of the
502.Cm o
503and
504.Cm p
505flags.
506.It Cm m
507Do not preserve file modification times.
508By default, file modification times are preserved whenever possible.
509.It Cm o
510Preserve the user ID and group ID.
511.It Cm p
512.Dq Preserve
513the file mode bits.
514This is intended to be used by a user with regular privileges
515who wants to preserve all aspects of the file other than the ownership.
516The file times are preserved by default, but two other flags are offered to
517disable this and use the time of extraction instead.
518.El
519.Pp
520In the preceding list,
521.Sq preserve
522indicates that an attribute stored in the archive is given to the
523extracted file, subject to the permissions of the invoking
524process.
525Otherwise the attribute of the extracted file is determined as
526part of the normal file creation action.
527If neither the
528.Cm e
529nor the
530.Cm o
531specification character is specified, or the user ID and group ID are not
532preserved for any reason,
533.Nm
534will not set the
535.Dv S_ISUID
536(setuid) and
537.Dv S_ISGID
538(setgid) bits of the file mode.
539If the preservation of any of these items fails for any reason,
540.Nm
541will write a diagnostic message to standard error.
542Failure to preserve these items will affect the final exit status,
543but will not cause the extracted file to be deleted.
544If the file characteristic letters in any of the string option-arguments are
545duplicated or conflict with each other, the one(s) given last will take
546precedence.
547For example, if
548.Fl p Ar eme
549is specified, file modification times are still preserved.
550.It Fl r
551Read an archive file from standard input
552and extract the specified
553.Ar file
554operands.
555If any intermediate directories are needed in order to extract an archive
556member, these directories will be created as if
557.Xr mkdir 2
558was called with the bitwise OR of
559.Dv S_IRWXU , S_IRWXG ,
560and
561.Dv S_IRWXO
562as the mode argument.
563When the selected archive format supports the specification of linked
564files and these files cannot be linked while the archive is being extracted,
565.Nm
566will write a diagnostic message to standard error
567and exit with a non-zero exit status at the completion of operation.
568.It Fl s Ar replstr
569Modify the archive member names according to the substitution expression
570.Ar replstr ,
571using the syntax of the
572.Xr ed 1
573utility regular expressions.
574.Ar file
575or
576.Ar pattern
577arguments may be given to restrict the list of archive members to those
578specified.
579.Pp
580The format of these regular expressions is:
581.Pp
582.Dl /old/new/[gp]
583.Pp
584As in
585.Xr ed 1 ,
586.Ar old
587is a basic regular expression (see
588.Xr re_format 7 )
589and
590.Ar new
591can contain an ampersand
592.Pq Ql & ,
593.Ql \e Ns Em n
594(where
595.Em n
596is a digit) back-references,
597or subexpression matching.
598The
599.Ar old
600string may also contain newline characters.
601Any non-null character can be used as a delimiter
602.Po
603.Ql /
604is shown here
605.Pc .
606Multiple
607.Fl s
608expressions can be specified.
609The expressions are applied in the order they are specified on the
610command line, terminating with the first successful substitution.
611.Pp
612The optional trailing
613.Cm g
614continues to apply the substitution expression to the pathname substring,
615which starts with the first character following the end of the last successful
616substitution.
617The first unsuccessful substitution stops the operation of the
618.Cm g
619option.
620The optional trailing
621.Cm p
622will cause the final result of a successful substitution to be written to
623standard error in the following format:
624.Pp
625.D1 Em original-pathname No >> Em new-pathname
626.Pp
627File or archive member names that substitute to the empty string
628are not selected and will be skipped.
629.It Fl T Ar range
630Allow files to be selected based on a file modification or inode change
631time falling within the specified time range.
632The range has the format:
633.Sm off
634.Bd -filled -offset indent
635.Op Ar from_date
636.Op \&, Ar to_date
637.Op / Oo Cm c Oc Op Cm m
638.Ed
639.Sm on
640.Pp
641The dates specified by
642.Ar from_date
643to
644.Ar to_date
645are inclusive.
646If only a
647.Ar from_date
648is supplied, all files with a modification or inode change time
649equal to or younger are selected.
650If only a
651.Ar to_date
652is supplied, all files with a modification or inode change time
653equal to or older will be selected.
654When the
655.Ar from_date
656is equal to the
657.Ar to_date ,
658only files with a modification or inode change time of exactly that
659time will be selected.
660.Pp
661When
662.Nm
663is in write or copy mode, the optional trailing field
664.Oo Cm c Oc Ns Op Cm m
665can be used to determine which file time (inode change, file modification or
666both) are used in the comparison.
667If neither is specified, the default is to use file modification time only.
668The
669.Cm m
670specifies the comparison of file modification time (the time when
671the file was last written).
672The
673.Cm c
674specifies the comparison of inode change time (the time when the file
675inode was last changed; e.g., a change of owner, group, mode, etc).
676When
677.Cm c
678and
679.Cm m
680are both specified, then the modification and inode change times are
681both compared.
682.Pp
683The inode change time comparison is useful in selecting files whose
684attributes were recently changed or selecting files which were recently
685created and had their modification time reset to an older time (as what
686happens when a file is extracted from an archive and the modification time
687is preserved).
688Time comparisons using both file times is useful when
689.Nm
690is used to create a time based incremental archive (only files that were
691changed during a specified time range will be archived).
692.Pp
693A time range is made up of six different fields and each field must contain two
694digits.
695The format is:
696.Pp
697.Dl [[[[[cc]yy]mm]dd]HH]MM[.SS]
698.Pp
699Where
700.Ar cc
701is the first two digits of the year (the century),
702.Ar yy
703is the last two digits of the year,
704the first
705.Ar mm
706is the month (from 01 to 12),
707.Ar dd
708is the day of the month (from 01 to 31),
709.Ar HH
710is the hour of the day (from 00 to 23),
711.Ar MM
712is the minute (from 00 to 59),
713and
714.Ar SS
715is the seconds (from 00 to 59).
716The minute field
717.Ar MM
718is required, while the other fields are optional and must be added in the
719following order:
720.Ar HH , dd , mm ,
721.Ar yy , cc .
722.Pp
723The
724.Ar SS
725field may be added independently of the other fields.
726Time ranges are relative to the current time, so
727.Ic -T 1234/cm
728would select all files with a modification or inode change time
729of 12:34 PM today or later.
730Multiple
731.Fl T
732time range can be supplied and checking stops with the first match.
733.It Fl t
734Reset the access times of any file or directory read or accessed by
735.Nm
736to be the same as they were before being read or accessed by
737.Nm pax .
738.It Fl U Ar user
739Select a file based on its
740.Ar user
741name, or when starting with a
742.Cm # ,
743a numeric UID.
744A
745.Ql \e
746can be used to escape the
747.Cm # .
748Multiple
749.Fl U
750options may be supplied and checking stops with the first match.
751.It Fl u
752Ignore files that are older (having a less recent file modification time)
753than a pre-existing file or archive member with the same name.
754During read,
755an archive member with the same name as a file in the file system will be
756extracted if the archive member is newer than the file.
757During write,
758a file system member with the same name as an archive member will be
759written to the archive if it is newer than the archive member.
760During copy,
761the file in the destination hierarchy is replaced by the file in the source
762hierarchy or by a link to the file in the source hierarchy if the file in
763the source hierarchy is newer.
764.It Fl v
765During a list operation, produce a verbose table of contents using the
766format of the
767.Xr ls 1
768utility with the
769.Fl l
770option.
771For pathnames representing a hard link to a previous member of the archive,
772the output has the format:
773.Pp
774.Dl Em ls -l listing No == Em link-name
775.Pp
776For pathnames representing a symbolic link, the output has the format:
777.Pp
778.Dl Em ls -l listing No -> Em link-name
779.Pp
780Where
781.Em ls -l listing
782is the output format specified by the
783.Xr ls 1
784utility when used with the
785.Fl l
786option.
787Otherwise for all the other operational modes
788(read, write, and copy),
789pathnames are written and flushed to standard error
790without a trailing newline
791as soon as processing begins on that file or
792archive member.
793The trailing newline
794is not buffered and is written only after the file has been read or written.
795.It Fl w
796Write files to the standard output
797in the specified archive format.
798When no
799.Ar file
800operands are specified, standard input
801is read for a list of pathnames with one per line without any leading or
802trailing
803.Aq blanks .
804.It Fl X
805When traversing the file hierarchy specified by a pathname,
806do not descend into directories that have a different device ID.
807See the
808.Li st_dev
809field as described in
810.Xr stat 2
811for more information about device IDs.
812.It Fl x Ar format
813Specify the output archive format, with the default format being
814.Cm pax .
815.Nm
816currently supports the following formats:
817.Bl -tag -width "sv4cpio"
818.It Cm bcpio
819The old binary cpio format.
820The default blocksize for this format is 5120 bytes.
821This format is not very portable and should not be used when other formats
822are available.
823Inode and device information about a file (used for detecting file hard links
824by this format), which may be truncated by this format, is detected by
825.Nm
826and is repaired.
827.It Cm cpio
828The extended cpio interchange format specified in the
829.St -p1003.2
830standard.
831The default blocksize for this format is 5120 bytes.
832Inode and device information about a file (used for detecting file hard links
833by this format), which may be truncated by this format, is detected by
834.Nm
835and is repaired.
836.It Cm sv4cpio
837The System V release 4 cpio.
838The default blocksize for this format is 5120 bytes.
839Inode and device information about a file (used for detecting file hard links
840by this format), which may be truncated by this format, is detected by
841.Nm
842and is repaired.
843.It Cm sv4crc
844The System V release 4 cpio with file CRC checksums.
845The default blocksize for this format is 5120 bytes.
846Inode and device information about a file (used for detecting file hard links
847by this format), which may be truncated by this format, is detected by
848.Nm
849and is repaired.
850.It Cm tar
851The old
852.Bx
853tar format as found in
854.Bx 4.3 .
855The default blocksize for this format is 10240 bytes.
856Pathnames stored by this format must be 100 characters or less in length.
857Only regular files, hard links, soft links, and directories
858will be archived (other file system types are not supported).
859For backwards compatibility with even older tar formats, a
860.Fl o
861option can be used when writing an archive to omit the storage of directories.
862This option takes the form:
863.Pp
864.Dl Fl o Cm write_opt=nodir
865.It Cm ustar
866The extended tar interchange format specified in the
867.St -p1003.2
868standard.
869The default blocksize for this format is 10240 bytes.
870Filenames stored by this format must be 100 characters or less in length;
871the total pathname must be 256 characters or less.
872.It Cm pax
873The pax interchange format specified in the
874.St -p1003.1-2001
875standard.
876The default blocksize for this format is 5120 bytes.
877.El
878.Pp
879.Nm
880will detect and report any file that it is unable to store or extract
881as the result of any specific archive format restrictions.
882The individual archive formats may impose additional restrictions on use.
883Typical archive format restrictions include (but are not limited to):
884file pathname length, file size, link pathname length, and the type of the
885file.
886.It Fl Y
887This option is the same as the
888.Fl D
889option, except that the inode change time is checked using the
890pathname created after all the file name modifications have completed.
891.It Fl Z
892This option is the same as the
893.Fl u
894option, except that the modification time is checked using the
895pathname created after all the file name modifications have completed.
896.It Fl z
897Use
898.Xr gzip 1
899to compress (decompress) the archive while writing (reading).
900Incompatible with
901.Fl a .
902.El
903.Pp
904The options that operate on the names of files or archive members
905.Po Fl c ,
906.Fl i ,
907.Fl j ,
908.Fl n ,
909.Fl s ,
910.Fl u ,
911.Fl v ,
912.Fl D ,
913.Fl G ,
914.Fl T ,
915.Fl U ,
916.Fl Y ,
917and
918.Fl Z
919.Pc
920interact as follows.
921.Pp
922When extracting files during a read operation, archive members are
923.Sq selected ,
924based only on the user specified pattern operands as modified by the
925.Fl c ,
926.Fl n ,
927.Fl u ,
928.Fl D ,
929.Fl G ,
930.Fl T ,
931.Fl U
932options.
933Then any
934.Fl s
935and
936.Fl i
937options will modify in that order, the names of these selected files.
938Then the
939.Fl Y
940and
941.Fl Z
942options will be applied based on the final pathname.
943Finally, the
944.Fl v
945option will write the names resulting from these modifications.
946.Pp
947When archiving files during a write operation,
948or copying files during a copy operation,
949archive members are
950.Sq selected ,
951based only on the user specified pathnames as modified by the
952.Fl n ,
953.Fl u ,
954.Fl D ,
955.Fl G ,
956.Fl T ,
957and
958.Fl U
959options (the
960.Fl D
961option only applies during a copy operation).
962Then any
963.Fl s
964and
965.Fl i
966options will modify in that order, the names of these selected files.
967Then during a copy operation the
968.Fl Y
969and the
970.Fl Z
971options will be applied based on the final pathname.
972Finally, the
973.Fl v
974option will write the names resulting from these modifications.
975.Pp
976When one or both of the
977.Fl u
978or
979.Fl D
980options are specified along with the
981.Fl n
982option, a file is not considered selected unless it is newer
983than the file to which it is compared.
984.Sh ENVIRONMENT
985.Bl -tag -width Ds
986.It Ev TMPDIR
987Path in which to store temporary files.
988.El
989.Sh EXIT STATUS
990.Ex -std pax
991.Sh EXAMPLES
992Copy the contents of the current directory to the device
993.Pa /dev/rst0 :
994.Pp
995.Dl $ pax -w -f /dev/rst0 \&.
996.Pp
997Give the verbose table of contents for an archive stored in
998.Pa filename :
999.Pp
1000.Dl $ pax -v -f filename
1001.Pp
1002This sequence of commands will copy the entire
1003.Pa olddir
1004directory hierarchy to
1005.Pa newdir :
1006.Bd -literal -offset indent
1007$ mkdir newdir
1008$ cd olddir
1009$ pax -rw . ../newdir
1010.Ed
1011.Pp
1012Extract files from the archive
1013.Pa a.pax .
1014Files rooted in
1015.Pa /usr
1016are extracted relative to the current working directory;
1017all other files are extracted to their unmodified path.
1018.Pp
1019.Dl $ pax -r -s ',^/usr/,,' -f a.pax
1020.Pp
1021This can be used to interactively select the files to copy from the
1022current directory to
1023.Pa dest_dir :
1024.Pp
1025.Dl $ pax -rw -i \&. dest_dir
1026.Pp
1027Extract all files from the archive
1028.Pa a.pax
1029which are owned by
1030.Em root
1031with group
1032.Em bin
1033and preserve all file permissions:
1034.Pp
1035.Dl $ pax -r -pe -U root -G bin -f a.pax
1036.Pp
1037Update (and list) only those files in the destination directory
1038.Pa /backup
1039which are older (less recent inode change or file modification times) than
1040files with the same name found in the source file tree
1041.Pa home :
1042.Pp
1043.Dl $ pax -r -w -v -Y -Z home /backup
1044.Sh DIAGNOSTICS
1045Whenever
1046.Nm
1047cannot create a file or a link when reading an archive or cannot
1048find a file when writing an archive, or cannot preserve the user ID,
1049group ID, or file mode when the
1050.Fl p
1051option is specified, a diagnostic message is written to standard error
1052and a non-zero exit status will be returned, but processing will continue.
1053In the case where
1054.Nm
1055cannot create a link to a file,
1056.Nm
1057will not create a second copy of the file.
1058.Pp
1059If the extraction of a file from an archive is prematurely terminated by
1060a signal or error,
1061.Nm
1062may have only partially extracted a file the user wanted.
1063Additionally, the file modes of extracted files and directories
1064may have incorrect file bits, and the modification and access times may be
1065wrong.
1066.Pp
1067If the creation of an archive is prematurely terminated by a signal or error,
1068.Nm
1069may have only partially created the archive, which may violate the specific
1070archive format specification.
1071.Pp
1072If while doing a copy,
1073.Nm
1074detects a file is about to overwrite itself, the file is not copied,
1075a diagnostic message is written to standard error
1076and when
1077.Nm
1078completes it will exit with a non-zero exit status.
1079.Sh SEE ALSO
1080.Xr cpio 1 ,
1081.Xr tar 1
1082.Sh STANDARDS
1083The
1084.Nm
1085utility is compliant with the
1086.St -p1003.1-2008
1087specification,
1088except that the
1089.Cm pax
1090archive format is only partially supported,
1091and the
1092.Cm listopt
1093keyword is unsupported.
1094.Pp
1095The flags
1096.Op Fl 0BDEGjOPTUYZz ,
1097the archive formats
1098.Cm bcpio ,
1099.Cm sv4cpio ,
1100.Cm sv4crc ,
1101and
1102.Cm tar ,
1103the
1104.Cm b , k ,
1105and
1106.Cm x
1107additions to the
1108.Fl b
1109flag,
1110and the flawed archive handling during list and read operations
1111are extensions to that specification.
1112.Sh HISTORY
1113A
1114.Nm
1115utility appeared in
1116.Bx 4.4 .
1117.Sh AUTHORS
1118.An Keith Muller
1119at the University of California, San Diego.
1120