Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux zip command: add a file with different name [closed]

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

like image 420
Luis Andrés García Avatar asked May 23 '13 09:05

Luis Andrés García


People also ask

How do I zip a file with a new name in Linux?

“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.

How do I add files to an existing zip file in Linux?

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.

How do I zip a directory and subdirectories in Linux?

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.


1 Answers

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.

like image 196
mkrnr Avatar answered Sep 17 '22 22:09

mkrnr