Score:0

How do I prevent zip from removing the leading slash when I am creating a zip file

sa flag

I am using zip on ubuntu 20.04 to create backup files which I then send to a backups device.

I use the following zip command : zip -r /tmp/stuff.zip /home/someone/stuff

to create a backup of the "stuff" directory. When I look at the contents of the generated zip file the leading slash has been removed from all of the zip file members. After reading the man page for zip I tried to use the "--absolute-path" option, but I received an error telling me that that option was not supported.

How can I prevent ZIP from removing the leading slash ?

Score:0
cn flag

How can I prevent ZIP from removing the leading slash ?

You can not and there are valid reasons for this. One of them the need to always check the contents 1st before extracting as you would never know up front it is has or has not a leading /.

It is hard-coded into all of those kind of tools. If you want this you will need to remove this feature from the source of "zip" and recompile it.

And there is a simple method to do what you want:

Extract the zip on any system by doing

cd /

and then do the extract command.

Mind that tar still has an option for this -P or --absolute-names. It will still default to restoring without absolute path if you restore without the option.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.