How to add files/folders to an existing TAR archive?

Is it possible to append on existing TAR archive?

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.

Syntax

tar -rf archive.tar file3.txt

This TAR archive contains two files file1.txt and file2.txt

See the example:

Test files;

[[email protected] ~]# touch file1.txt
[[email protected] ~]# touch file2.txt
[[email protected] ~]# touch file3.txt

TAR archive;
[[email protected] ~]# tar -cvf archive.tar file1.txt file2.txt

Listing files in archive using -t

[[email protected] ~]# tar -tf archive.tar
file1.txt
file2.txt

Adding a file to TAR archive

[[email protected] ~]# tar -rf archive.tar file3.txt

Check now!

[[email protected] ~]# tar -tf archive.tar
file1.txt
file2.txt
file3.txt

That’s it dude!!

Read also

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

15+ tar command usages with examples – Unix/Linux

This is one of the most commonly using Linux command. This is very similar to the ZIP concept in Windows platform, what we are using commonly to save multiple file together.

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.

Here I am explaining some common and useful switches and it usages with examples. Also, by using TAR we can compress and decompress files and make a single file archive to transfer file. In Linux almost all packages are available in internet in TAR file format. READ MORE..

Post navigation

Arunlal Ashok

Linux Systems Architect at Endurance International Group. I know her (Linux) since many years. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

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 CryBit.com

Leave a Reply

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