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