I read that tar -A means: add archives to the end of an existing archive; tar -r means: append files to the end of a tar archive. Do they not mean the same thing? Could anyone please explain the difference between these two?
tar -A
takes two or more tarballs and concatenates them:
tar -A -f tarball1.tar tarball2.tar
adds the contents of tarball2.tar
to tarball1.tar
.
tar -r
adds files to a tarball:
tar -r -f tarball1.tar file1
adds file1
to tarball1.tar
, as a file inside it alongside its other contents.
Here’s a more detailed example:
$ touch file1 file2 file3
$ tar cf tar1.tar file1 file2
$ tar cf tar2.tar file3
$ cp tar1.tar tar3.tar
$ tar Af tar1.tar tar2.tar
$ tar tf tar1.tar
file1
file2
file3
$ tar rf tar3.tar file3
$ tar tf tar3.tar
file1
file2
file3
Note how we end up with the same contents in two different ways. If you used tar -r
with multiple tarballs, you’d end up with the added tarballs inside the receiving tarball, as-is, not “unwrapped”.
-A
withtar
. You seem to be talking about a vendor specific option fromgtar
. – schily Sep 12 '18 at 22:20gtar
when they refer to incompatible gtar enhancements. There are still UNIX platforms around that will not acceptgtar
options and this is primarily a UNIX portal. – schily Nov 21 '19 at 13:17