Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am taring a folder and for some reason the entire directory structure that preceds the folder I am tarring is included.

I am doing this in a script like:

'tar czf ' + dir + '/asdf.tgz ' + dir + 'asdf/'

Where dir is like:

/Downloads/archive/

In the man pages, I see I can fix this but I can't get it to work.

I tried:

tar czf -C dir ...

But now I have some kind of a file -C in my folder (which I can't seem to delete btw!).

Please help!

share|improve this question

1 Answer 1

up vote 3 down vote accepted
  1. The single-character options must be followed immediately by their parameters, then any other parameters. Otherwise, use normal style options or combine the -C the same way.

    tar cvCf dir asdf.tgz asdf

    tar -c -v -f dir/asdf.tgz -C dir asdf

  2. Since programs read - as meaning an option character, you need to defeat this to access a file starting with -. Two ways to do this:

    rm -- -C

    rm ./-C

share|improve this answer
    
thanks dude!..... –  Blankman Apr 12 '12 at 22:14
    
I'm getting a failed to open '~/path/to', here is my command: tar czfC ~/path/to/asdf.tgz asdf/ –  Blankman Apr 12 '12 at 22:20
    
That command doesn't look right; as written you have told it to use archive ~/path/to/asdf.tgz, then change directory to asdf/, but no files to add to the archive (which should produce an error message). –  geekosaur Apr 12 '12 at 22:29
    
ok I don't understand why the order matters, I thought cvCf are just options that you are passing, compress, verbose, f etc... –  Blankman Apr 13 '12 at 20:44
    
C and F both want pathname arguments. They don't mean the same thing, so you'd kinda like to know which name goes with which option, yes? –  geekosaur Apr 13 '12 at 20:56

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.