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?

  • There is no option names -A with tar. You seem to be talking about a vendor specific option from gtar. – schily Sep 12 '18 at 22:20
  • GNU tar is a fairly reasonable assumption, given the Linux tag. – Jeff Schaller Sep 13 '18 at 1:19
  • It would help a lot if people did write gtar when they refer to incompatible gtar enhancements. There are still UNIX platforms around that will not accept gtar options and this is primarily a UNIX portal. – schily Nov 21 '19 at 13:17

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
$ tar rf tar3.tar file3
$ tar tf tar3.tar

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”.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.