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.
Thanks
“rename zip file in linux” Code Answer To use mv to rename a file type mv , a space, the name of the file, a space, and the new name you wish the file to have.
Sometimes it's easy to delete a ZIP file and create a new one – say you've forgotten to include a file. Just drag it into the folder to be ZIPped up and start again.
The easiest way to zip a folder on Linux is to use the “zip” command with the “-r” option and specify the file of your archive as well as the folders to be added to your zip file. You can also specify multiple folders if you want to have multiple directories compressed in your zip file.
You can use zipnote which should come with the zip package.
First build the zip archive with the myfile.txt file:
zip archive.zip myfile.txt
Then rename myfile.txt inside the zip archive with:
printf "@ myfile.txt\n@=myfile2.txt\n" | zipnote -w archive.zip
(Thanks to Jens for suggesting printf
instead of echo -e
.)
A short explanation of "@ myfile.txt\n@=myfile2.txt\n"
:
From zipnote -h
: "@ name" can be followed by an "@=newname" line to change the name
And \n
separates the two commands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With