我创建了tar存档,其中包含保存文件的绝对路径.
/home/mydir/dir1/dir2/dir3/file1.dat
/home/mydir/dir1/dir2/dir3/file2.dat
/home/mydir/dir1/dir2/dir3/file3.dat
我想解开这些档案,跳过路径的前导部分/ home / mydir / dir1.我的文件应该在具有以下结构的任何目录中恢复:
dir2/dir3/file1.dat
dir2/dir3/file2.dat
dir2/dir3/file3.dat
如何使用tar命令或其他方式执行此操作?
解决方法:
如果您使用的是GNU tar,那么可以选择删除一些
提取时的前导路径成员:
`--strip-components=number'
Strip given number of leading components from file names before extraction.
For example, suppose you have archived whole `/usr' hierarchy to a
tar archive named `usr.tar'. Among other files, this archive
contains `usr/include/stdlib.h', which you wish to extract to the
current working directory. To do so, you type:
$tar -xf usr.tar --strip=2 usr/include/stdlib.h
在您的情况下,–strip = 3应该适用.