我只想提取 tar 文件文件夹中的文件
例子:
tar 文件内容:
/home/parent_dir/child_dir/
我只想将 child_dir 中的文件提取到另一个目录
命令
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
。
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