tar -u vs -r

How are they different? I get duplicate entries with either. I would expect from reading the man page that -r would append files no matter what so dupicates to be expected. But -u should only add the new file if it is di

Code:
cweimann@hp800g3:~ $ tar cf test.tar test1.txt
cweimann@hp800g3:~ $ tar -u -f test.tar test2.txt
cweimann@hp800g3:~ $ tar -u -f test.tar test2.txt
cweimann@hp800g3:~ $ tar -u -f test.tar test2.txt
cweimann@hp800g3:~ $ tar tvf test.tar
-rw-r--r--  0 cweimann cweimann    2 Sep 13 21:11 test1.txt
-rw-r--r--  0 cweimann cweimann   11 Sep 13 21:12 test2.txt
-rw-r--r--  0 cweimann cweimann   11 Sep 13 21:12 test2.txt
-rw-r--r--  0 cweimann cweimann   11 Sep 13 21:12 test2.txt
cweimann@hp800g3:~ $

From man page of tar
Code:
     -u      Like -r, but new entries are added only if they have a
             modification date newer than the corresponding entry in the
             archive.  Note that this only works on uncompressed archives
             stored in regular files.  The -f option is required.  The long
             form is --update.
 
Last edited by a moderator:
Same behavior here. Judging by what the man page says, this seems like a bug.

I'm running a stock FreeBSD 13.3, and this is the version of tar: bsdtar 3.6.2 - libarchive 3.6.2 zlib/1.3.1 liblzma/5.4.5 bz2lib/1.0.8 libzstd/1.4.8

If you have nothing better to do, you could file a PR.
 
there seems to be a bug / feature
when comparing mtime for exclusion file nanoseconds are compared too
since the fs supports it and ustar file format wont it will fail because most likely the value on the fs is non zero
if you test like tar -cvf a.tar a.c -uvf will add a.c over and over again
if you do tar xvf a.tar and then try -uvf will work (will extract with m_time_nanosec 0)
if you tar --format=pax will work as intended
also there seems to be a problem when first / is removed
tar uvf x.tar /bin wont work but tar uvf x.tar -C / bin will work (with format pax)
 
Back
Top