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.