如何在 Unix/Linux 中使用 tar 将文件提取到不同的目录

通常我们提取压缩文件都是在同一目录中,但是如果我们需要在其他位置提取它怎么办?

你只需要添加一个另外的参数 -C指定要解压到的文件夹

# tar -xzvf file.tar.gz -C /destination/path

例如

# pwd
/home
# tar -czvf test.tar.gz test/

现在我们的测试目录已经被压缩。
让我们将它解压到 /tmp 中。

[root@test home]# tar -xzvf test.tar.gz -C /tmp/
# cd /tmp
# ls -l
drwx------. 4 test test 4096 Sep 28 12:46 test
日期:2020-06-02 22:18:31 来源:oir作者:oir