tar command - how to extract one file to specific directory

I think The C option to tar should occur earlier in the command

tar -cvf - -C /tmp path/to.myfile

I imagine you could download, compile and install GNU tar into your ~/bin, which might make things a bit easier.


That command worked for me fine as you said you tried with the -C first: tar -C /tmp -xvf. Maybe it's a bug in your tar version?

A little clunky, but there's always:

cd /tmp
gunzip -c /path/to/mytargzfile.tgz | tar xvf - path/to/myfile

I recommend installing GNU tar for yourself. It's worth it just for the -j and -z options if nothing else, and is one of the first things I always do in a new Unix account.