2

I'm talk about the "ar" command in Linux/UNIX which is used for creating or managing archives.

According to the manual, we can move members in an archive with "m" modifier. But there isn't any example.

The manual page just say "If no modifiers are used with m, any members you name in the member arguments are moved to the end of the archive;", so I guess it should work like this (and I was successful):

$ 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
$

File "a.txt" was successfully moved to the end.

But when it comes to "you can use the a, b, or i modifiers to move them to a specified place instead", I got problem:

$ 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
$

I thought "a" means move ahead, while "b" move backward, "i" move to index, there might be a number after the modifier. So I tried:

$ 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" is still moved to the end!

And when I want to move a file backward, it was still moved to 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
$

So how to use it?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Vespene Gas
  • 163
  • 1
  • 6

1 Answers1

3

From the GNU ar documentation on my OpenBSD system explaining the a modifier:

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.

That is, you need to specify the name of the archive member to move the entry after (or before with b). The POSIX specification of ar spells it out in the description of posname (called relpos in the GNU documentation):

posname

The name of a file in the archive, used for relative positioning; see options -m and -r.

Testing this (using standard options with -):

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

Move a.txt to after c.txt:

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

The i modifier is an alias for b.

POSIX mentions this too:

-i

Position new files in the archive before the file in the archive named by the posname operand (equivalent to -b).

Kusalananda
  • 320,670
  • 36
  • 633
  • 936