Bootstrap FreeKB - TAR - append to an archive
TAR - append to an archive

Updated:   |  TAR articles

Let's say the /tmp directory contains one file, foo.txt.

/tmp/foo.txt

 

Let's say you've created a tar archive named example.tar, and the tar archive contains the contents of the /tmp directory.

tar -cf example.tar /tmp

 

The tar command with the -t or --list and -f or --file optiions can be used to view the contents of the tar achive.

tar -tf example.tar

 

Let's say the following is returned, meaning that example. tar contains one file, foo.txt.

tmp/
tmp/foo.txt

 

Let's say another file is added to the /tmp directory, bar.txt.

touch /tmp/bar.txt

 

The --append and --preserve-permissions and --file options can be used to append files to an existing archive. In this example, /tmp/bar.txt is appended to example.tar.

You wouldn't want to use just /tmp here, as this would append all of the files in the /tmp directory to example.tar, even if example.tar already contains one or more of the files in the /tmp directory

tar --appendĀ --preserve-permissionsĀ --file example.tar /tmp/bar.txt

 

Or, more commonly, the -rpf flag is used.

tar -rpf example.tar /tmp/bar.txt

 

The tar command with the -t or --list and -f or --file optiions can be used to view the contents of the tar achive.

tar -tf example.tar

 

Now example.tar should contain both foo.txt and bar.txt.

tmp/
tmp/foo.txt
tmp/bar.txt



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter c08241 in the box below so that we can be sure you are a human.