0

The following command:

tar -C "${HOME}/temp" -zcvf uber-bundle.tgz temp

fail with the following error:

tar: temp: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

However a slightly different command works, albeit generating a tar with incorrect directory structure:

tar -C "${HOME}/temp" -zcvf uber-bundle.tgz ~/temp
tar: Removing leading `/' from member names
...

It is clear that -C option fail to change the current directory of tar to ${HOME}, making directory unrecognizable. What went wrong and how to fix it?

3

What happens here is that -C option tells tar to change directory first before creating an archive. So in the first example what you are doing is this pretty much:

cd /home/whatever/temp/; tar -zcvf uber-bundle.tgz temp;

Now are you sure you have an additional 'temp' directory in this path '/home/whatever/temp/'

In the second instance since you are using absolute path ~/temp as tar argument, even though tar changed your directory to '/home/whatever/temp/' it operates on the argument of ~/temp so you are doing this:

cd /home/whatever/temp/; tar -zcvf uber-bundle.tgz ~/temp;

So in this case the problem is that you are creating tar archive of directory you are currently in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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