How to add files/folders to an existing TAR archive?
Is it possible? Yes we can add additional files/folders to an already existing TAR archive. The ‘TAR’ saves many files together into a single tape or disk archive, and can restore individual files from the archive. It is very useful in such conditions like when we want to send a lot of files via email, transfer files from one machine to another etc. We already discussed the the basic switches of TAR command in one previous session. Click here for more details TAR command usages. Here I’m explaining one of the useful TAR switch. It will help you to add more files/folders into an existing TAR archive.
The “-r or –append” option with TAR command will do this.
tar -rf archive.tar file3.txt
This TAR archive contains two files file1.txt and file2.txt
See the example:
## Creating three files;
[root@vps ~]# touch file1.txt [root@vps ~]# touch file2.txt [root@vps ~]# touch file3.txt
## Creating a TAR archive;
[root@vps ~]# tar -cvf archive.tar file1.txt file2.txt
## Listing files in archive using -t
[root@vps ~]# tar -tf archive.tar file1.txt file2.txt
## Adding a file to TAR archive
[root@vps ~]# tar -rf archive.tar file3.txt
## Check now!
[root@vps ~]# tar -tf archive.tar file1.txt file2.txt file3.txt
That’s it dude!!