Extract a single file from a tar file to another directory

Hi,

I need to extract a single file from a tar file to another directory.

So far I have this:

This one extract a single file to same directory:

tar -xvf filename.tar ./file.txt

I tried this but its not working

tar -xvf filename.tar /home/dir ./file.txt

or this:

tar -xvf filename.tar -C /home/dir ./file.txt

This works fine for me:

tar -C dir -xf filename.tar file.txt

Emanuele

it didn't work.

Usage: tar -{c|r|t|u|x} [ -BdDEFhilmopRUsvwZ ] [ -Number ] [ -f TarFil e ]
           [ -b Blocks ] [ -S [ Feet ] | [ Feet@Density ] | [ Blocksb ] ]
           [ -L InputList ] [-X ExcludeFile] [ -N Blocks ] [ -C Directory ] File ...
Usage: tar {c|r|t|u|x} [ bBdDEfFhilLXmNopRsSUvwZ[0-9] ] ]
           [ Blocks ] [ TarFile ] [ InputList ] [ ExcludeFile ]
           [ [ Feet ] | [ Feet@Density ] | [ Blocksb ] ] [-C Directory ] File ...

$> tar -tf filename.tar
file1
file2
file3
$> mkdir dir
$> tar -C dir/ -xf filename.tar file1
$> ls dir/
file1

Different version?

$> tar --version
tar (GNU tar) 1.26
...

how do I know the version of my tar?

List the archive first

tar tf filename.tar

The extracted file name must exactly match!

I'm pretty sure the file name does match