tarを使用して別のディレクトリに抽出する方法は?

tarを使用して別のディレクトリに抽出する方法は?

これはうまくいきません:

tar xf /tmp/foo.tar.gz foo/bar
tar: foo/bar: Not found in archive

ファイルを所定の位置に抽出して移動する以外に何をすべきかは不明です。

ベストアンサー1

からman tar

     -C directory
         In c and r mode, this changes the directory before adding the
         following files.  In x mode, change directories after opening the
         archive but before extracting entries from the archive.

つまり、tar xC /foo/bar -f /tmp/foo.tar.gz作業を完了する必要があります。 (FreeBSDではただし、GNU tarはこの点で基本的に同じです。マニュアルの「作業ディレクトリの変更」を参照してください。)

おすすめ記事