AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1544265
Accepted
SomePerson
SomePerson
Asked: 2020-04-22 11:23:26 +0800 CST2020-04-22 11:23:26 +0800 CST 2020-04-22 11:23:26 +0800 CST

如何使用命令行工具“解压缩”只抓取某个文件夹?

  • 772

我有一个 .jar 文件,可以使用命令行工具“解压缩”打开它,它调用了这个选项,-p因此您可以获取某些文件。但是你如何用文件夹来做到这一点?这是这个 jar 文件的结构。

My.jar
|-folder
|   |-Content
|        |-My Files
|   |-First Folder
|        |-Second Folder
|             |-Files
|-image.png
|-foo.class
|-bar.class

我想抓取的文件夹“文件夹”也比“我的文件”和“文件”有更多的文件。

我试过的命令:unzip dir/to\ a\ folder/My.jar -d dir/to\ a/desired\ folder -p folder/ | image.png

没有其他文件:unzip dir/to\ a\ folder/My.jar -d dir/to\ a/desired\ folder -p folder/

我用jar命令尝试了这个,这似乎有效,但我特别想用unzip.

我得到的错误是:

注意:文件名不匹配:-p
注意:文件名不匹配:assets/,

解压缩帮助菜单我有: 在 macOS 10.13.6 上解压

command-line command-line-arguments
  • 1 1 个回答
  • 719 Views

1 个回答

  • Voted
  1. Best Answer
    pmqs
    2020-04-23T00:16:55+08:002020-04-23T00:16:55+08:00

    很好,这只是unzip您正在运行的标准 info-zip。

    您使用的-p选项没有达到您的预期。下面是-p.

       -p     extract files to pipe (stdout).  Nothing but the  file  data  is
              sent  to  stdout,  and  the files are always extracted in binary
              format, just as they are stored (no conversions).
    

    让我们举个例子。首先创建一个和你的类似的目录树

    data
    `-- folder
        `-- Content
            |-- FirstFolder
            |   `-- SecondFolder
            |       `-- Files
            |           |-- f1
            |           |-- f2
            |           `-- f3
            `-- MyFiles
                |-- a1
                |-- a2
                `-- a3
    

    把它塞进拉链里

    $ zip -r try.zip data
    $ unzip -l data.zip
    Archive:  try.zip
      Length      Date    Time    Name
    ---------  ---------- -----   ----
            0  04-22-2020 08:59   data/
            0  04-22-2020 08:59   data/file1
            0  04-22-2020 08:59   data/file2
            0  04-22-2020 08:56   data/folder/
            0  04-22-2020 08:57   data/folder/Content/
            0  04-22-2020 08:57   data/folder/Content/FirstFolder/
            0  04-22-2020 08:57   data/folder/Content/FirstFolder/SecondFolder/
            0  04-22-2020 08:57   data/folder/Content/FirstFolder/SecondFolder/Files/
            0  04-22-2020 08:57   data/folder/Content/FirstFolder/SecondFolder/Files/f2
            0  04-22-2020 08:57   data/folder/Content/FirstFolder/SecondFolder/Files/f1
            0  04-22-2020 08:57   data/folder/Content/FirstFolder/SecondFolder/Files/f3
            0  04-22-2020 08:57   data/folder/Content/MyFiles/
            0  04-22-2020 08:57   data/folder/Content/MyFiles/a3
            0  04-22-2020 08:57   data/folder/Content/MyFiles/a1
            0  04-22-2020 08:57   data/folder/Content/MyFiles/a2
            0  04-22-2020 08:59   data/file3
    ---------                     -------
            0                     16 files
    

    如果只想提取folder子树,则需要提供unzip与子树匹配的通配符。在这种情况下data/folder/*会成功。

    $ unzip -d output try.zip 'data/folder/*' 
    Archive:  try.zip
       creating: output/data/folder/
       creating: output/data/folder/Content/
       creating: output/data/folder/Content/FirstFolder/
       creating: output/data/folder/Content/FirstFolder/SecondFolder/
       creating: output/data/folder/Content/FirstFolder/SecondFolder/Files/
     extracting: output/data/folder/Content/FirstFolder/SecondFolder/Files/f2  
     extracting: output/data/folder/Content/FirstFolder/SecondFolder/Files/f1  
     extracting: output/data/folder/Content/FirstFolder/SecondFolder/Files/f3  
       creating: output/data/folder/Content/MyFiles/
     extracting: output/data/folder/Content/MyFiles/a3  
     extracting: output/data/folder/Content/MyFiles/a1  
     extracting: output/data/folder/Content/MyFiles/a2  
    
    • 2

相关问题

  • 如何使用键盘快捷键在 macOS 终端中选择一行?

  • 如何在 macOS 的终端中切换切换(连续性)?

  • Windows 上是否有可以通过 CMD 或 Powershell 提供加密安全随机字节的设备或可执行文件?

  • Python 的“pass”参数的批处理等价物是什么?

  • 禁用后无法启用 Microsoft Print to PDF

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve