Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I observe the following behavior with both tar 1.26 and 1.27.1:

$ mkdir a b a/diffowner
$ sudo mkdir b/diffowner
$ sudo chmod a+w b/diffowner
$ echo foo > a/diffowner/foo
$ tar -C a -cvf test.tar diffowner
diffowner/
diffowner/foo
$ tar -C b -xvf test.tar diffowner
diffowner/
diffowner/foo
tar: diffowner: Cannot utime: Operation not permitted
tar: diffowner: Cannot change mode to rwxr-xr-x: Operation not permitted
tar: Exiting with failure status due to previous errors

So what I'm trying to do here is extracting a tar file into an existing directory structure, where I'm not the owner of all the directories involved but I do have write permission on all of them. In fact they are shared among a group.

I don't care about timestamps, and I trust that permissions should be correct already. I'm running this as a normal user so it shouldn't be trying to --preserve-permissions unless told so, which I did not. What really does worry me is the exit status: I intend to use this in a script, and want to know whether the actual extraction worked fine.

Is there an option to tar which tells it not to set directory permissions, neither immediately nor delayed? Failing that, what other solutions would you suggest. Right now I'm thinking about extracting to a temporary directory and using rsync to move stuff into the existing tree. But perhaps you know a less hackish approach.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

This tar option might be what you're looking for:

 --no-overwrite-dir
       preserve metadata of existing directories

I tested as follows:

$ mkdir a b a/diffowner
$ sudo mkdir b/diffowner
$ sudo chmod a+w b/diffowner
$ echo foo > a/diffowner/foo
$ tar -C a -cvf test.tar diffowner
diffowner/
diffowner/foo
$ tar -C b --no-overwrite-dir -xvf test.tar diffowner
diffowner/
diffowner/foo
$ echo $?
0
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.