Question regarding tar command.

I wish my tar -xf hello.tar command should return successful even if the tar has already been extracted at the same location i.e. exists by the same or a different user.

Currently i am getting this error as another user has extracted the same tar at the same location.

tar: README - cannot create
tar: output.txt- cannot create
tar: printed - cannot create
........

Below two option do not work for me for the reasons stated.

tar -xf hello.tar 2>/dev/null just suppresses the error and echo $? does not return zero(successful).

tar -xf hello.tar || true returns success even if the tar file does not exists or other non desired errors.

I did read the man page and look at option -u but that does not help my case.

Can you please suggest if i can get the untar to return success even if the untar has already been done by same or different user.

How far did you get when reading the man page? man tar :

1 Like

If the tar archive has already been extracted by another user, who is that user? When you try it what account are you running under? root??

It could well be that when you try to extract the archive, the files already extracted by the other user do not give you the access rights to overwrite/create/modify them.

1 Like

Both my users are non root users.

I tried tar -xf hello.tar --overwrite and that seems to persist the existing extracted files with its user owner be it files or folders.

So i guess the --overwrite option works for me & is for both files and folders.

The man page does not mention about the --overwrite option anywhere.

I am happy to have a resolution to the query and i consider this resolved.

You should not need the --overwrite option.
The --no-overwite (in GNU tar) will make tar more happy.

Or you must have a common-group-writable (or world-writable) directory without a t-bit. (E.g. /tmp has got a t-bit, as you can see with ls -ld ).
Warning: a shared writable directory without t-bit allows ALL commands to change or delete other users' files.

And i wish i had better thought-through questions to answer. Seems like we both don't get what we want.

How should tar know it "has already been extracted", hmm?

  • how would tar know at all, because if the pathes in an archive are relative the archive could have been unpacked into a very different place in the filesystem;

  • even if there are some files matching the name of files in the archive - how would tar find out if they are complete or if some are missing?

  • even if the unpacked file collection is complete, how would tar find out if they are of the same content as the ones in the archive (that is,without actually unpacking them all and running a - hypothetical - "binary diff " against every one of them?

  • and even if such a hypothetical analysis would turn out to be successful, how would tar make sure the surely existing diferences in inode content (mtime, ctime, owner, whatever) doesn't matter? Which (amount of) difference exactly should tar tolerate and still consider a specific pair of files (in- and outside the archive) to be equal?

What you want: doesn't exist, is theoretically impossible (and actually against the law of thermodynamics, so its safe to say it will never exist). Does that answer your question?

I hope this helps.

bakunin

2 Likes

Helped :slight_smile: