Linux zip 命令:添加不同名称的文件 [英] Linux zip command: add a file with different name
问题描述
我想在 zip 文件中添加一个具有不同名称的文件,并避免创建具有所需名称的新文件.例如,我想将 myfile.txt 文件添加到 zip,但将其重命名为 myfile2.txt.
I´d like to add a file in a zip file, with a different name, and avoiding the creation of a new file with the desired name. For example, I´d like to add the myfile.txt file to a zip, but renaming it to myfile2.txt.
谢谢
推荐答案
你可以使用zip包自带的zipnote.
You can use zipnote which should come with the zip package.
首先使用 myfile.txt 文件构建 zip 存档:
First build the zip archive with the myfile.txt file:
zip archive.zip myfile.txt
然后将 zip 存档中的 myfile.txt 重命名为:
Then rename myfile.txt inside the zip archive with:
printf "@ myfile.txt
@=myfile2.txt
" | zipnote -w archive.zip
(感谢 Jens 建议使用 printf
而不是 echo -e代码>.)
(Thanks to Jens for suggesting printf
instead of echo -e
.)
"@myfile.txt
@=myfile2.txt
"的简短说明
:
A short explanation of "@ myfile.txt
@=myfile2.txt
"
:
来自zipnote -h
:@name"后面可以跟一个@=newname"行来更改名称
From zipnote -h
: "@ name" can be followed by an "@=newname" line to change the name
而
将两个命令分开.
And
separates the two commands.
这篇关于Linux zip 命令:添加不同名称的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!