pax (读取和写入归档文件的内容,而与归档文件格式无关)

瑞兹 发表于 2020-11-04 09:11
浏览次数:
在手机上阅读

在类似Unix的操作系统上,pax命令读取和写入归档文件的内容,而与归档文件格式无关。

查看英文版

目录

1 pax 运行系统环境

2 pax 描述

3 pax 语法

4 pax 例子

pax 运行系统环境

Linux

pax 描述

本文档介绍了paxLinux版本。

“ Pax”是“便携式归档交换”的缩写。该软件支持许多主要的存档格式。它可以读取每个文件的内容,并将它们写入新的单个存档中。

This document covers the Linux version of pax.

"Pax" is short for "portable archive interchange." The software support many major archive formats. It can read the contents of each, and write them to a new, single archive.

查看英文版

查看中文版

pax 语法

pax [-c] [-d] [-n] [-v] [-f archive] [-s replstr] [pattern]
pax -r [-c] [-d] [-i] [-k] [-n] [-u] [-v] [-f archive] [ -o options] 
    [-p string] [-s replstr] [pattern]
pax -w [-d] [-i] [-t] [-u] [-v] [-X] [-b blocksize] [-a] i [-f archive] 
    [-o options] [-s replstr] [-x format] [file]
pax -r -w [-d] [-i] [-k] [-l] [-n] [-t] [-u] [-v] [-X] [-p string] 
    [-s replstr] [file] directory
-C 匹配所有文件或归档成员,但模式或文件操作数指定的成员除外。
-d 导致目录类型的文件被复制或归档,或者目录类型的归档成员被提取为仅匹配文件或归档成员本身,而不匹配根于该文件的文件层次结构。
-n 选择与每个模式操作数匹配的第一个存档成员。每种模式最多只能匹配一个存档成员(尽管类型为directory的成员仍将匹配以该文件为根的文件层次结构)。
-v 在列表模式下,生成详细的目录(请参见标准输出)。否则,将存档成员路径名写入标准错误(请参见标准错误)。
-r 从标准输入中读取存档文件。
-i 交互式重命名文件或存档成员。对于每个与模式操作数匹配的存档成员或与文件操作数匹配的文件,将在文件/ dev / tty中写入提示。该提示将包含文件或存档成员的名称。然后从/ dev / tty中读取一行。如果此行为空,则将跳过文件或存档成员。如果此行包含单个句点,则将在不修改文件名或文件名的情况下对其进行处理。否则,其名称将替换为该行的内容。在PAX命令将立即以非零退出状态退出,如果-的文件末尾读取响应时遇到或者的/ dev / tty的不能打开阅读和写作。
-k 防止覆盖现有文件。
-l 链接文件。在复制模式下,将尽可能在源文件层次结构和目标文件层次结构之间建立硬链接。
-u 忽略比相同名称的现有文件或归档成员更旧的文件(文件修改时间更短)。

阅读模式 如果存档成员比文件新,则将提取与文件系统中文件名称相同的存档成员。
写模式 如果文件比存档成员新,则与文件系统中文件名称相同的存档文件成员将被取代。
复制模式 如果源层次结构中的文件较新,则目标层次结构中的文件将被源层次结构中的文件或源层次结构中文件的链接替换。
-t 使归档文件的访问时间与pax读取之前的访问时间相同。
-X 遍历路径名指定的文件层次结构时,pax不会下降到具有不同设备ID(st_dev)的目录中。
-w 将文件以指定的存档格式写入标准输出。
-a 将文件追加到归档文件的末尾。该选项不适用于某些存档设备,例如1/4英寸流磁带和8mm磁带。
-f archive 指定输入或输出归档文件的路径名,以覆盖默认的标准输入(在列表或读取模式下)或标准输出(在写模式下)。
-s replstr 使用替换表达式replstr修改基于模式或文件操作数命名的文件或归档成员名称,该替换表达式基于ed s(替代)命令,使用则表达式手册页上的则表达式语法。在pax命令的上下文中,“地址”和“行”的概念无意义,因此不能提供。格式为:

-s /old/new/ [gp]

其中,如在edold是一个基本的正则表达式和新可以包含符号(“  ‘)或’ \ n ”反向引用,其中Ñ是一个数字。还允许旧字符串包含换行符。

任何非空字符都可以用作分隔符(此处显示“ / ”)。可以指定多个-s表达式;表达式将以指定的顺序应用,并以第一个成功替换结束。可选的尾随ged命令中所定义。可选的尾随p会导致成功替换写入标准错误。读写档案时,将替换为空字符串的文件或档案成员名称。

-b blocksize 每次写入存档文件时,以正十进制整数字节形式阻止输出。设备和存档格式可能会对阻止施加限制。根据输入自动确定阻塞。可移植应用程序不得指定大于32256的块大小值。创建档案时的默认阻止取决于档案格式。(请参阅下面的-x选项。)
-o options 保留用于特定于格式的特殊选项。
-p string 指定一个或多个文件特征选项(特权)。字符串选项参数必须是一个字符串,该字符串指定要在提取时保留或丢弃的文件特征。该字符串由规范字符aemop组成。可以在同一字符串中串联多个特征,并且可以指定多个-p选项。规范字符的含义如下:

a 不保留文件访问时间。
e 保留用户ID,组ID,文件模式位,访问时间和修改时间。
m 不要保留文件修改时间。
o 保留用户ID和组ID。
p 保留文件模式位。可以保留其他与实现相关的文件模式属性。

在前面的列表中,“保留”表示将根据调用过程的权限将档案中存储的属性赋予提取的文件;否则,该属性将被确定为正常文件创建操作的一部分。

如果未指定eo规范字符,或者由于任何原因未保留用户ID和组ID,则pax将不会设置文件模式的setuid和setgid位。

如果任何这些项目的保存由于任何原因而失败,pax都会将诊断消息写入标准错误。无法保留这些项目将影响最终退出状态,但不会导致提取的文件被删除。

如果任何字符串选项参数中的文件特性字母重复或彼此冲突,则最后给出的字母优先。例如,如果指定-p eme,则将保留文件修改时间。

-x format 指定输出存档格式。在PAX命令识别以下格式:

cpio 扩展的cpio交换格式;请参阅IEEE 1003.1(1990)规范。字符特殊存档文件的此格式的默认块大小为5120。实现支持所有小于或等于32256的值(均为512的倍数)的块大小。

此存档格式允许将UID和GID最多为262143的文件存储在存档中。UID和GID大于此值的文件将以UID和GID为60001存档。
Ustar 扩展的tar交换格式;请参阅IEEE 1003.1(1990)规范。对于字符特殊存档文件,此格式的默认块大小为10240。实现支持所有小于或等于32256的块大小值,该值是512的倍数。

任何以不同于现有存档格式的格式追加到存档文件的尝试都会导致pax立即以非零退出状态退出。

这种存档格式允许UID和GID最高为2097151的文件存储在存档中。UID和GID大于此值的文件将以UID和GID为60001存档。
pattern 一种与归档成员的一个或多个路径名匹配的模式。模式必须符合在fnmatch手册页上找到的模式匹配符号。如果未指定模式,则默认值为选择存档中的所有成员。
file 要复制或归档的文件的路径名。
directory 复制模式的目标目录路径名。
pax [-c] [-d] [-n] [-v] [-f archive] [-s replstr] [pattern]
pax -r [-c] [-d] [-i] [-k] [-n] [-u] [-v] [-f archive] [ -o options] 
    [-p string] [-s replstr] [pattern]
pax -w [-d] [-i] [-t] [-u] [-v] [-X] [-b blocksize] [-a] i [-f archive] 
    [-o options] [-s replstr] [-x format] [file]
pax -r -w [-d] [-i] [-k] [-l] [-n] [-t] [-u] [-v] [-X] [-p string] 
    [-s replstr] [file] directory
-c Match all file or archive members except those specified by the pattern or file operands.
-d Cause files of type directory being copied or archived or archive members of type directory being extracted to match only the file or archive member itself and not the file hierarchy rooted at the file.
-n Select the first archive member that matches each pattern operand. No more than one archive member will be matched for each pattern (although members of type directory will still match the file hierarchy rooted at that file).
-v In list mode, produce a verbose table of contents (see Standard Output). Otherwise, write archive member path names to standard error (see Standard Error).
-r Read an archive file from standard input.
-i Interactively rename files or archive members. For each archive member matching a pattern operand or file matching a file operand, a prompt will be written to the file /dev/tty. The prompt will contain the name of the file or archive member. A line will then be read from /dev/tty. If this line is blank, the file or archive member will be skipped. If this line consists of a single period, the file or archive member will be processed with no modification to its name. Otherwise, its name will be replaced with the contents of the line. The pax command will immediately exit with a non-zero exit status if end-of-file is encountered when reading a response or if /dev/tty cannot be opened for reading and writing.
-k Prevent the overwriting of existing files.
-l Link files. In copy mode, hard links will be made between the source and destination file hierarchies whenever possible.
-u Ignore files that are older (having a less recent file modification time) than a pre-existing file or archive member with the same name.

read mode an archive member with the same name as a file in the file system will be extracted if the archive member is newer than the file.
write mode an archive file member with the same name as a file in the file system will be superseded if the file is newer than the archive member.
copy mode the file in the destination hierarchy will be replaced by the file in the source hierarchy or by a link to the file in the source hierarchy if the file in the source hierarchy is newer.
-t Cause the access times of the archived files to be the same as they were before being read by pax.
-X When traversing the file hierarchy specified by a path name, pax will not descend into directories that have a different device ID (st_dev).
-w Write files to the standard output in the specified archive format.
-a Append files to the end of the archive. This option will not work for some archive devices, such as 1/4-inch streaming tapes and 8mm tapes.
-f archive Specify the path name of the input or output archive, overriding the default standard input (in list or read modes) or standard output (write mode).
-s replstr Modify file or archive member names named by pattern or file operands according to the substitution expression replstr, which is based on the ed s (substitution) command, using the regular expression syntax on the regex manual page. The concepts of "address" and "line" are meaningless in the context of the pax command, and must not be supplied. The format is:

-s/old/new/[gp]

where, as in edold is a basic regular expression and new can contain an ampersand ("&") or a "\n" backreference, where n is a digit. The old string also is permitted to contain newline characters.

Any non-null character can be used as a delimiter ( "/" is shown here). Multiple -s expressions can be specified; the expressions will be applied in the order specified, terminating with the first successful substitution. The optional trailing g is as defined in the ed command. The optional trailing p causes successful substitutions to be written to standard error. File or archive member names that substitute to the empty string are ignored when reading and writing archives.

-b blocksize Block the output at a positive decimal integer number of bytes per write to the archive file. Devices and archive formats may impose restrictions on blocking. Blocking is automatically determined on input. Portable applications must not specify a blocksize value larger than 32256. Default blocking when creating archives depends on the archive format. (See the -x option below.)
-o options Reserved for special format-specific options.
-p string Specify one or more file characteristic options (privileges). The string option-argument must be a string specifying file characteristics to be retained or discarded on extraction. The string consists of the specification characters aemo, and p. Multiple characteristics can be concatenated within the same string and multiple -p options can be specified. The meaning of the specification characters are as follows:

a Do not preserve file access times.
e Preserve the user ID, group ID, file mode bits, access time, and modification time.
m Do not preserve file modification times.
o Preserve the user ID and group ID.
p Preserve the file mode bits. Other, implementation-dependent file-mode attributes may be preserved.

In the preceding list, "preserve" indicates that an attribute stored in the archive will be given to the extracted file, subject to the permissions of the invoking process; otherwise, the attribute will be determined as part of the normal file creation action.

If neither the e nor the o specification character is specified, or the user ID and group ID are not preserved for any reason, pax will not set the setuid and setgid bits of the file mode.

If the preservation of any of these items fails for any reason, pax will write a diagnostic message to standard error. Failure to preserve these items will affect the final exit status, but will not cause the extracted file to be deleted.

If file-characteristic letters in any of the string option-arguments are duplicated or conflict with each other, the ones given last will take precedence. For example, if -p eme is specified, file modification times will be preserved.

-x format Specify the output archive format. The pax command recognizes the following formats:

cpio The extended cpio interchange format; see the IEEE 1003.1(1990) specifications. The default blocksize for this format for character special archive files is 5120. Implementations support all blocksize values less than or equal to 32256 that are multiples of 512.

This archive format allows files with UIDs and GIDs up to 262143 to be stored in the archive. Files with UIDs and GIDs greater than this value will be archived with the UID and GID of 60001.
ustar The extended tar interchange format; see the IEEE 1003.1(1990) specifications. The default blocksize for this format for character special archive files is 10240. Implementations support all blocksize values less than or equal to 32256 that are multiples of 512.

Any attempt to append to an archive file in a format different from the existing archive format will cause pax to exit immediately with a non-zero exit status.

This archive format allows files with UIDs and GIDs up to 2097151 to be stored in the archive. Files with UIDs and GIDs greater than this value will be archived with the UID and GID of 60001.
pattern A pattern matching one or more path names of archive members. A pattern must conform to the pattern matching notation found on the fnmatch manual page. The default, if no pattern is specified, is to select all members in the archive.
file A path name of a file to be copied or archived.
directory The destination directory path name for copy mode.

查看英文版

查看中文版

pax 例子

pax -w -f /dev/rmt/1m

将当前目录的内容复制到中等密度的磁带机1。

pax -w -f /dev/rmt/1m

Copies the contents of the current directory to tape drive 1, medium density.

查看英文版

查看中文版

其他命令行

pack | pagesize | parted | partprobe | paste | passwd | pcat | pg | perl | pgrep | pico | pine | ping | pr | printenv | priocntl | printf | pstree | pvs | pwd |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条