ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: Zip and 7Zip

    IT Discussion
    linux zip 7zip compression archiver sam linux administration system administration scottalanmiller
    3
    6
    3.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      Linux users often must work with files coming from, or going to, Windows users. Compressed Archive files are one of the more common files that need to be managed between the two platforms. Windows users often struggle to work with the Linux native compression formats (gzip, bzip2 and xz) unless they use a third party tool, such as 7Zip.

      Linux has the tools to work with Windows' formats, however, so this task is quite simple. On Linux the very standard zip utility handles compatibility with standard Windows compression and archiving "zip" format and p7zip allows us to work with Compressed Archives in the common 7Zip format.

      Let's say that we have a folder called stuff that contains things that we want to archive and compress together into a single Zip archive.

      zip -r stuff.zip stuff
      

      This will zip up the contents of stuff, the -r means recursive and is needed for the normal use case, and save it as stuff.zip. Now things can easily be sent to a Windows user. Notice that the zip utility does not replace the original folder. So, like with tar, you will use additional disk space for this operation.

      Unzipping is even easier.

      unzip stuff.zip
      

      The p7zip utility is even easier. Let's take our stuff directory again and use the 7zip format.

      p7zip stuff
      

      That is all that we need. The command outputs stuff.7z. To decompress, though, we use a different format than with the other compression and archival commands.

      p7zip -d stuff.7z
      

      The -d flag is for decompress. Very easy to use as well. The Zip and 7Zip formats are not really suitable for use as UNIX utilities as they do not gather UNIX filesystem metadata. They are meant for use for transferring archives between systems where the metadata is not needed, such as from a UNIX system to Windows or vice versa.

      Part of a series on Linux Systems Administration by Scott Alan Miller

      1 Reply Last reply Reply Quote 1
      • KellyK
        Kelly
        last edited by

        If you're working with only Linux would you keep using tar, or use one of the above commands?

        scottalanmillerS 1 Reply Last reply Reply Quote 0
        • scottalanmillerS
          scottalanmiller @Kelly
          last edited by scottalanmiller

          @Kelly said in Linux: Zip and 7Zip:

          If you're working with only Linux would you keep using tar, or use one of the above commands?

          You would stay with tar. The tar utility maintains the UNIX filesystem metadata and is native to all platforms. The zip utility is commonly added to a Linux distro and 7zip lessso. But tar you will always have and it works better.

          1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller
            last edited by

            Using tar gives you often better compression, too. Or faster, depending on what you want.

            tar -xzvf stuff.tgz /folder
            tar -xjvf stuff.tgj /folder
            tar -xJvf staff.tgx /folder
            

            You can use those forms for gzip, bzip2 or xz compression options. All normally beat Windows Zip, xz is the same as 7zip, bzip2 is often the best option.

            1 Reply Last reply Reply Quote 2
            • tonyshowoffT
              tonyshowoff
              last edited by

              Sorry if this was mentioned but I didn't see it directly mentioned for clarity:

              If your compression is unavailable directly in tar (-J being essentially 7zip, my favourite), you can tar it first (without compression) and then compress the tar, this maintains both Unix metadata and also gives the benefit.

              Also, if you compress something already compressed you won't get the best benefit, at least not when it comes to using something as powerful as LZMA/7zip.

              scottalanmillerS 1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller @tonyshowoff
                last edited by

                @tonyshowoff said in Linux: Zip and 7Zip:

                Sorry if this was mentioned but I didn't see it directly mentioned for clarity:

                If your compression is unavailable directly in tar (-J being essentially 7zip, my favourite), you can tar it first (without compression) and then compress the tar, this maintains both Unix metadata and also gives the benefit.

                Also, if you compress something already compressed you won't get the best benefit, at least not when it comes to using something as powerful as LZMA/7zip.

                I believe that that is mentioned in the tar article.

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post