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

## Adding a file to TAR archive

[root@vps ~]# tar -rf archive.tar file3.txt

## Check now!

[root@vps ~]# tar -tf archive.tar

That’s it dude!!

Read also

1, 20+ Rsync command switches
2, Tar command with example
3, LSOF command details

Post navigation

Arunlal Ashok

Cloud Infrastructure / DevOps Engineer. I'm dealing Linux servers since 2012. I started this blog to share and discuss my ideas.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team

Leave a Reply

Your email address will not be published. Required fields are marked *