解压缩如何修剪顶级目录


14

我有一个zip存档。该unzip -l myarchive.zip命令给出以下清单:

top/subtop/files/1.txt
top/subtop/files2/2.txt
etc

根文件夹位于所有文件的顶部/子顶部。如何在没有两个top / subtop文件夹的情况下提取这些文件?

例如,当我在/ home / myuser的/ public_html目录,files/1.txtfiles2/2.txt768,16直接解压到该目录。

我尝试过,unzip myarchive.zip top/subtop/*但是无论如何它创建了顶层/子顶层目录。

Answers:


9

不幸的是,你不能。您唯一真正的选择是在提取它们之后才移动它们。


嗯,很高兴知道。我之所以这样问,是因为几天前创建存档时,它是无意中从上方添加了一些路径。因此,由于存在额外的顶部路径,因此无法解压缩它们。但是,我今天不能重复此操作-今天工作正常,即在top / subtop目录中并执行zip -r files.zip *时,不会将top / subtop路径作为文件路径的前缀添加。我认为我执行的命令完全相同,但是奇怪的是结果不同,因此在解压缩时不必剥离顶级目录。
camcam'7

请注意,可以使用忽略所有目录(只需将所有文件彼此相邻放置)unzip -j
Skylar Ittner

4

您可能想尝试该tar命令,该命令具有--strip-components功能并且可以对zip文件进行操作。


2
不适用于tar(GNU tar)1.15.1:tar: This does not look like a tar archive tar: Error exit delayed from previous errors
Kevin Panko 2014年

2
FreeBSD的tar可以处理ZIP归档文件。不幸的是,其他tar实现功能不那么完整。
Mikhail T.

1
对于debian用户,如果您想使用tar解压缩zip文件,则FreeBSD的tar可作为bsdtar(apt-get install bsdtar)使用。
尼古拉斯·B


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.