~/Downloads/t1$ tar tf test.t
home/a/Downloads/t2/
home/a/Downloads/t2/z.txt
home/a/Downloads/t2/y.txt
~/Downloads/t1$ tar xf test.t
~/Downloads/t1$ ls ~/Downloads/t2
ls: cannot access ’/home/a/Downloads/t2’: No such file or directory 为什么会发生这种事?是因为我没有给出路径名吗?
发布于 2020-10-29 21:40:05
尝试从您解压的tar存档目录中提取ls home/a/Downloads/t2/。
注意,在tar t列表中,路径没有前导斜杠,因此在提取存档时,它们将相对于当前工作目录,而不是相对于文件系统根目录。通常,这是您想要的,因为从档案中提取文件到任何地方都是相当危险的。
当然,在创建存档时,通常使用tar cf foo.tar t2而不是tar cf foo.tar /home/a/t2来存储路径的相关部分。
但是,由于存档中已经有更长的路径,所以可以( a)转到根目录提取它:
~$ cd /
/$ tar xf ~/Downloads/t1/test.t 或者使用一个选项让tar删除不需要的部分,例如,至少在GNU中:
提取时,从文件名中提取
--strip-components=NUMBER带数引导组件。
所以,tar xf test.t --strip-components=3应该能做到。
https://unix.stackexchange.com/questions/617104
复制相似问题