linuxbashcompressiontar

How to update tar (NOT append)


I want to update an existing tar file with newer files.

At GNU, I read:

4.2.3 Updating an Archive

In the previous section, you learned how to use ‘--append’ to add a file to an existing archive. A related operation is ‘--update’ (‘-u’). The ‘--update’ operation updates a tar archive by comparing the date of the specified archive members against the date of the file with the same name. If the file has been modified more recently than the archive member, then the newer version of the file is added to the archive (as with ‘--append’).

However, When I run my tar update command, the files are appended even though their modification dates are exactly the same. I want to ONLY append where modification dates of files to be tarred are newer than those already in the tar...

tar -uf ./tarfile.tar /localdirectory/ >/dev/null 2>&1

Currently, every time I update, the tar doubles in size...


Solution

  • Warning! When speaking about "dates" it means any date, and that includes the access time.

    Should your files have been accessed in any such way (a simple ls -l is enough) then tar is right to do what it does!

    You need to find another way to do what you want. Probably use a sentinel file and see if its modification date is less than the files you wish to append.