ar 命令移动成员(有例子吗?)

ar 命令移动成员(有例子吗?)

我谈论的是 Linux/UNIX 中用于创建或管理档案的“ar”命令。

根据手册,我们可以使用“m”修饰符移动存档中的成员。但没有任何例子。

手册页只是说“如果 m 没有使用任何修饰符,则您在成员参数中命名的任何成员都将移动到存档的末尾;”,所以我想它应该像这样工作(并且我成功了):

$ ar -t out.a
a.txt
b.txt
c.txt
d.txt
$ ar m out.a a.txt
$ ar -t out.a
b.txt
c.txt
d.txt
a.txt
$

文件“a.txt”已成功移动到末尾。

但是当谈到“你可以使用 a、b 或 i 修饰符将它们移动到指定位置”时,我遇到了问题:

$ ar t out.a
a.txt
b.txt
c.txt
d.txt
$ ar ma out.a a.txt
ar: a.txt: File format not recognized
$

我以为“a”表示向前移动,而“b”表示向后移动,“i”移动到索引,修饰符后面可能会有一个数字。所以我尝试:

$ ar t out.a
a.txt
b.txt
c.txt
d.txt
$ ar ma 1 out.a a.txt
$ ar t out.a
b.txt
c.txt
d.txt
a.txt
$

“a.txt”仍然移到最后!

当我想向后移动文件时,它仍然被移动到 then end:

$ ar t out.a
a.txt
b.txt
c.txt
d.txt
$ ar mb 1 out.a c.txt
$ ar t out.a
a.txt
b.txt
d.txt
c.txt
$

那么如何使用呢?

答案1

ar我的 OpenBSD 系统上的GNU文档解释一下a修改器:

a   Add new files after an existing member of the archive.  If you use
    the modifier a, the name of an existing archive member must be
    present as the relpos argument, before the archive specification.

也就是说,您需要指定姓名归档成员的以将条目移动到之后(或之前 b)。POSIX 规范 ar在( GNU 文档中posname称为)的描述中详细说明了这一点:relpos

posname

存档中文件的名称,用于相对定位;请参阅选项-m和 -r

对此进行测试(使用带有 的标准选项-):

$ ar -t out.a
a.txt
b.txt
c.txt
d.txt

移至a.txt之后c.txt

$ ar -m -a c.txt out.a a.txt
$ ar -t out.a
b.txt
c.txt
a.txt
d.txt

i修饰符是 的别名b

POSIX 也提到了这一点:

-i

将存档中的新文件放置在由操作数命名的存档中的文件之前posname(相当于 -b)。

相关内容