Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
    
Wondering if there's a way to do this at tar creation time as opposed to extraction..? – Roy Truelove Mar 22 at 18:06
up vote 7 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .