我可以将 zip 档案中特定文件夹的文件提取到当前文件夹吗?
我尝试使用
unzip archive.zip folder/*
但是我在当前目录中找到了文件夹“folder”。如何将“folder”中的文件提取到当前目录中?
答案1
根据答案这里您可以使用单引号'
将要提取的文件夹括起来。用于-j
垃圾路径,这意味着不会重新创建档案的目录结构。用于指定要将其提取到哪个文件夹。下面显示了通过运行此行从包含多个文件夹的档案中-d
提取文件夹名称中的文件夹:1992
unzip -j archive.zip 'folder/to/extract/*' -d 'where/to/extract/to/'
例子:
terrance@terrance-ubuntu:/media/500GB$ unzip -l Holiday\ Lemmings\ Pack
Archive: Holiday Lemmings Pack.zip
Length Date Time Name
--------- ---------- ----- ----
0 2004-10-07 23:39 Holiday Lemmings 1993/
3597 1993-11-11 11:11 Holiday Lemmings 1993/ADLIB.DAT
252 1993-11-11 11:11 Holiday Lemmings 1993/GREET.DAT
1056 1993-11-11 11:11 Holiday Lemmings 1993/GROUND1O.DAT
1056 1993-11-11 11:11 Holiday Lemmings 1993/GROUND2O.DAT
16157 1993-11-11 11:11 Holiday Lemmings 1993/INSTALL.EXE
3143 1993-11-11 11:11 Holiday Lemmings 1993/LEVEL000.DAT
2868 1993-11-11 11:11 Holiday Lemmings 1993/LEVEL001.DAT
3033 1993-11-11 11:11 Holiday Lemmings 1993/LEVEL002.DAT
5654 1993-11-11 11:11 Holiday Lemmings 1993/LEVEL003.DAT
59775 1993-11-11 11:11 Holiday Lemmings 1993/MAIN.DAT
3560 1993-11-11 11:11 Holiday Lemmings 1993/TANDYSND.DAT
25902 1993-11-11 11:11 Holiday Lemmings 1993/VGAGR1.DAT
33123 1993-11-11 11:11 Holiday Lemmings 1993/VGAGR2.DAT
31520 1993-11-11 11:11 Holiday Lemmings 1993/VGALEMMI.EXE
0 2004-10-07 23:39 Holiday Lemmings 1994/
6894 1995-07-04 14:20 Holiday Lemmings 1994/ADLIB.DAT
438 1995-07-04 14:20 Holiday Lemmings 1994/GREET.DAT
1056 1995-07-04 14:20 Holiday Lemmings 1994/GROUND1O.DAT
1056 1995-07-04 14:20 Holiday Lemmings 1994/GROUND2O.DAT
38 1995-07-04 14:20 Holiday Lemmings 1994/LEMMINGS.BAT
2432 1995-07-04 14:20 Holiday Lemmings 1994/LEVEL000.DAT
2633 1995-07-04 14:20 Holiday Lemmings 1994/LEVEL001.DAT
3433 1995-07-04 14:20 Holiday Lemmings 1994/LEVEL002.DAT
3401 1995-07-04 14:20 Holiday Lemmings 1994/LEVEL003.DAT
3143 1995-07-04 14:20 Holiday Lemmings 1994/LEVEL004.DAT
2868 1995-07-04 14:20 Holiday Lemmings 1994/LEVEL005.DAT
3033 1995-07-04 14:20 Holiday Lemmings 1994/LEVEL006.DAT
5654 1995-07-04 14:20 Holiday Lemmings 1994/LEVEL007.DAT
58577 1995-07-04 14:20 Holiday Lemmings 1994/MAIN.DAT
5470 1995-07-04 14:20 Holiday Lemmings 1994/TANDYSND.DAT
25902 1995-07-04 14:20 Holiday Lemmings 1994/VGAGR1.DAT
33123 1995-07-04 14:20 Holiday Lemmings 1994/VGAGR2.DAT
31610 1995-07-04 14:20 Holiday Lemmings 1994/VGALEMMI.EXE
0 2004-10-07 23:39 X-Mas Lemmings 1991/
3597 1991-12-03 14:19 X-Mas Lemmings 1991/ADLIB.DAT
8164 1991-12-07 14:47 X-Mas Lemmings 1991/CLOSING.EXE
1056 1991-11-11 16:13 X-Mas Lemmings 1991/GROUND0O.DAT
1056 1991-12-03 10:08 X-Mas Lemmings 1991/GROUND2O.DAT
11057 1991-12-03 14:51 X-Mas Lemmings 1991/INSTALL.EXE
756 1991-11-14 09:26 X-Mas Lemmings 1991/LEMMINGS.BAT
2552 1991-12-03 17:40 X-Mas Lemmings 1991/LEVEL000.DAT
59992 1991-12-03 15:24 X-Mas Lemmings 1991/MAIN.DAT
8602 1991-12-07 14:45 X-Mas Lemmings 1991/OPENING.EXE
3560 1991-12-03 14:25 X-Mas Lemmings 1991/TANDYSND.DAT
28701 1991-12-03 17:44 X-Mas Lemmings 1991/TGAL.EXE
74 1991-12-05 18:16 X-Mas Lemmings 1991/TGALEMMI.BAT
15981 1991-12-03 10:26 X-Mas Lemmings 1991/TGAMAIN.DAT
17957 1991-11-29 11:43 X-Mas Lemmings 1991/VGAGR0.DAT
33123 1991-11-29 11:44 X-Mas Lemmings 1991/VGAGR2.DAT
30469 1991-12-03 17:44 X-Mas Lemmings 1991/VGAL.EXE
74 1991-12-05 18:16 X-Mas Lemmings 1991/VGALEMMI.BAT
0 2004-10-07 23:39 X-Mas Lemmings 1992/
3597 1991-12-03 14:19 X-Mas Lemmings 1992/ADLIB.DAT
10126 1992-11-30 11:31 X-Mas Lemmings 1992/CLOSING.EXE
1056 1991-12-03 10:08 X-Mas Lemmings 1992/GROUND2O.DAT
28 1992-10-29 15:04 X-Mas Lemmings 1992/HELP.BAT
492 1991-07-24 14:00 X-Mas Lemmings 1992/INSTALL.BAT
763 1992-10-29 15:03 X-Mas Lemmings 1992/LEMMINGS.BAT
2201 1992-11-25 11:55 X-Mas Lemmings 1992/LEVEL000.DAT
59992 1991-12-03 15:24 X-Mas Lemmings 1992/MAIN.DAT
16153 1991-12-03 14:51 X-Mas Lemmings 1992/MENU.EXE
8733 1992-11-30 11:29 X-Mas Lemmings 1992/OPENING.EXE
3560 1991-12-03 14:25 X-Mas Lemmings 1992/TANDYSND.DAT
33123 1991-11-29 11:44 X-Mas Lemmings 1992/VGAGR2.DAT
30469 1991-12-03 17:44 X-Mas Lemmings 1992/VGAL.EXE
77 1992-11-30 11:36 X-Mas Lemmings 1992/VGALEMMI.BAT
--------- -------
778598 67 files
我想要提取的是1992
名称中包含以下内容的文件夹到名为的文件夹中1992/
:
terrance@terrance-ubuntu:/media/500GB$ unzip -j Holiday\ Lemmings\ Pack.zip '*1992/*' -d '1992/'
Archive: Holiday Lemmings Pack.zip
inflating: 1992/ADLIB.DAT
inflating: 1992/CLOSING.EXE
inflating: 1992/GROUND2O.DAT
extracting: 1992/HELP.BAT
inflating: 1992/INSTALL.BAT
inflating: 1992/LEMMINGS.BAT
inflating: 1992/LEVEL000.DAT
inflating: 1992/MAIN.DAT
inflating: 1992/MENU.EXE
inflating: 1992/OPENING.EXE
inflating: 1992/TANDYSND.DAT
inflating: 1992/VGAGR2.DAT
inflating: 1992/VGAL.EXE
inflating: 1992/VGALEMMI.BAT
terrance@terrance-ubuntu:/media/500GB$ cd 1992/
terrance@terrance-ubuntu:/media/500GB/1992$ ls
ADLIB.DAT HELP.BAT LEVEL000.DAT OPENING.EXE VGALEMMI.BAT
CLOSING.EXE INSTALL.BAT MAIN.DAT TANDYSND.DAT VGAL.EXE
GROUND2O.DAT LEMMINGS.BAT MENU.EXE VGAGR2.DAT
答案2
你可以通过以下方式
unzip archive.zip folder/*; mv folder/* .;rm -r folder
我认为没有可以unzip
直接执行此操作的选项。
为了使其更短
f=folder; unzip archive.zip $f; mv $f .;rm -r $f
或者作为脚本
#!/bin/sh
unzip $1 $2
mv $2 .
rm -r $2
以 身份运行script.sh archive.zip folder
。