If you want to restore the file's metadata from the archive, be able to restore files of any type (including symlinks) and with arbitrary names, and also choose the new name of the file, you could use libarchive's bsdtar
(which also supports ZIP format archives) instead of unzip
as:
bsdtar -nqvvxpf file.zip -'s/.*/newname/S' some/dir/originalname
Note: like in unzip
, the some/dir/originalname
there is taken as a shell wildcard pattern. So if the path of archive member you want to extract does contain *
, ?
, \
or [
characters, you'll need to escape them as in:
bsdtar -nqvvxpf file.zip -'s/.*/newname/S' 'som[?]/dir/[*]riginalname'
or:
bsdtar -nqvvxpf file.zip -'s/.*/newname/S' 'som\?/dir/\*riginalname'
if the archive member is called som?/dir/*riginalname
.
Note that that approach would work with any of the archive formats supported by libarchive, not just zip.
jar
file? – Naftuli Kay Jun 01 '11 at 01:01.jar
; if your file is named differently you might need to tell AVFS to use its zip handler, e.g.~/.avfs$PWD/foo.apk#uzip/META-INF
. – Gilles 'SO- stop being evil' Jun 01 '11 at 07:19-p
extracts the file as-is (-c
does text conversion). – Gilles 'SO- stop being evil' Jun 01 '11 at 20:50