【问题标题】:How to extract files inside a directory from a tar file in terminal?如何从终端中的 tar 文件中提取目录中的文件?
【发布时间】:2010-05-13 02:08:34
【问题描述】:

我只想提取 tar 文件文件夹中的文件

例子:

tar 文件内容:

  • /home/parent_dir/child_dir/

我只想将 child_dir 中的文件提取到另一个目录

【问题讨论】:

    标签: unix terminal extract tar


    【解决方案1】:

    命令

    tar xf tarfile.tar /home/parent_dir/child_dir
    

    只会提取child_dir及其下属中的文件。

    如果 /home/parent_dir/child_dir 不是您希望它们出现的位置,GNU tar 提供了一个 --transform 选项,其用法如下:

    tar  --transform 's,/home/parent_dir/child_dir,foo,' --show-transformed -xf tarfile.tar
    

    这会将原本进入/home/parent_dir/child_dir 的文件放入./foo

    【讨论】:

      【解决方案2】:

      cd <another_directory>
      tar xvf <path_to_tar>/<tarfile>.tar <child_dir>
      例如
      cd <parent_directory>
      tar cvf test.tar *
      tar tf test.tar
      查看您想要的文件夹。例如src/org
      cd <some other directory you want to extract to>
      tar xvf ..\test.tar src/org
      ls
      您现在将看到您从 tar 获取的目录,例如src/org

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-17
        • 2015-11-01
        • 1970-01-01
        • 2010-09-23
        • 1970-01-01
        • 2014-09-10
        相关资源
        最近更新 更多