In the last tutorial we looked a look at compressing archives. We continues look at GNU tar and this time we look at appending and combining tar archives.
Appending to Archives
Appending and combining tar archives are similar so we have added them to the same tutorial, however, they are covered individually as they are not the same. If you have an existing archive to which you want to add new files, this can be done using the long option of –append or the short option of -r. This will append files to an archive. If the need is to joint two archives together then the option –-concatenate should be used. We will look at appending to archives first. We will start by creating a new archives and then add a file to it.
$ tar --create --file=my.tar /etc/services tar: Removing leading `/' from member names $ tar --list --file=my.tar etc/services $ tar --append --file=my.tar /etc/hosts tar: Removing leading `/' from member names $ tar --list --file=my.tar etc/services etc/hosts
This becomes a great option where we need to keep all related file togther once they have been worked on. You can imagine crrating a series of scripts that perform related activities. Once a script has been completed it can be appended to the application archive.
Of course, more than one file or directory can be appended to the archive, what we see here is a just a simple example.
Combining Archives
As we mentioned before, if we need to combine two or more archives we can use the –concatenate option or -A. The archives must be combined to an existing archive which is specified with the –file option. Any amount of archives can be combined to the single archive specified.In this example we create two new archives and combine then together into the single archive.
$ tar --create --file=file1.tar /etc/hosts /etc/hostname tar: Removing leading `/' from member names $ tar --list --file=file1.tar etc/hosts etc/hostname $ tar --create --file=file2.tar /etc/services tar: Removing leading `/' from member names $ tar --list --file=file2.tar etc/services $ tar --concatenate --file=file1.tar file2.tar $ tar --list --file=file1.tar etc/hosts etc/hostname etc/services
The video follows: