25

I unzipped a file on my server using:

unzip filename

However this seems to have caused all the files having owner/group permissions of 0 0.

The files I uploaded were a PHP software script, so I'm wondering how I set the permissions properly when unzipping the files and what they should be set to?

1
  • Usually, the Unix unzip restores file permissions. It may be that the ZIP file has been created without file permissions stored (probably with something other than Unix zip). In that case, restoring would obviously not be possible.
    – caw
    Commented May 22, 2021 at 2:34

2 Answers 2

13

Zip doesn't support saving file ownership/permission as far as I know. You can try setting the umask so unzip should create the files with these permissions. Run

umask 644

before unzip.

8
  • 1
    It was actually zipped with window, sorry.
    – Brett
    Commented Jun 3, 2013 at 10:31
  • 2
    It doesn't matter if it was created on windows or *nix. Zip still doesn't support unix file permissions. Regardless where it was created.
    – lawl0r
    Commented Jun 3, 2013 at 10:33
  • Yeah, I know.... but you said I could try setting the umask so it would create the zip with these permissions; but don't think I can do that on windows?
    – Brett
    Commented Jun 3, 2013 at 10:40
  • 1
    Before unziping
    – lawl0r
    Commented Jun 3, 2013 at 10:41
  • 13
    @lawl0r yes it does. Use the -Z option to see them.
    – OrangeDog
    Commented Jul 27, 2015 at 16:31
42

Actually, some answers here are not correct. ZIP files can also have file permissions. (*) You can list the permissions of the files in your ZIP file with:

unzip -Z

Maybe the tool you used to create the ZIP file didn't store the permissions or didn't store them correctly.

So, if you made the ZIP file yourself, check the tool you made the ZIP file with. Maybe there is a way to set permissions before zipping (like with maven), or it preserves the original permissions (but that would only work on a system that supports permissions - i.e. not on Windows).

If you didn't make the ZIP file yourself, your only chance is to set the correct the permissions after unzipping, for example with

chmod -R [permissions] [directory]

(*) We use that feature in combination with the maven assembly plugin, where you can specify the fileMode for files that go into the ZIP file.

7
  • 1
    i think you are right, but the way how you propose the answer it not right. you should focus to provide a good answer than criticize in a new one... Commented Jul 14, 2015 at 15:20
  • 2
    @FranciscoTapia I updated my answer (with some things one could try), but I'll leave the hint that other answers are incorrect in there. I think it's important. Commented Jul 22, 2015 at 7:38
  • 2
    UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. on Windows / mingw. I currently don't have access to my linux box, but there -Z works too. Anyway, thanks for the hint! Commented Dec 23, 2015 at 11:15
  • 4
    @David Tanzer, your answer is the best even while it's not accepted. Indeed, the origin of an archive (e.g. Windows, Linux, etc) is important. I've tested on Linux (Zip 3.0, UnZip 6.00). Once a file is put into an archive the permissions are saved. And they being restored on the extracted file (e.g. when the file is extracted on Linux). Obviously, the permissions will be not applied when extracting on Windows box. It will be really cool to see in unzip a specific switch (like tar's --no-same-permissions) that doesn't preserve permissions and respects umask while extracting.
    – flaz14
    Commented Jun 6, 2017 at 17:58
  • 1
    @DanielF Permissions are only there if the creating program put them there, so if your archive was created on Windows, zipinfo/unzip -Z can only guess. To see if the permissions are there, use zipinfo -v/unzip -Zv and look for “non-MSDOS external file attributes”; the two most significant bytes are the UNIX permissions (in hex, not octal!) provided the “file system or operating system of origin” is UNIX. Commented Apr 10, 2019 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .