zip and unzip are linux commands line that often used to accomplish administrative tasks on “Terminal”. “zip” is used to compress your files into a zip archive, while “unzip” is to extract the zipped files from a zip archive 🗄️. This program is useful for packaging a set of files for distribution, archiving files, and saving disk space by temporarily compressing files or directories.

The terminal is a user interactive and outputs the results of “zip and unzip” commands which are specified by the user itself. Execution of typed command is done only after you press the Enter key. It has the power and flexibility, means that using it may be essential.

How to ZIP and UNZIP on Linux

zip unzip are typically packaged in a linux distribution for supporting system includes Debian, Fedora, Centos, OpenSUSE, Arch Linux, Ubuntu and many others, allowing modifications to the original files or directories 📁. You can easily zip or unzip files or directories on linux via terminal on your system with the following methods.

ZIP on Linux

zip is a compression and file packaging utility for Unix, VMS, MSDOS, OS/2, Windows, Minix, Atari, Macintosh, Amiga, and Acorn RISC OS. It is analogous to a combination of the Unix commands tar and compress and is compatible with MSDOS systems.

To zip one or more file(s) and folder(s) / directory via terminal on Linux:

  1. Open “Terminal” or by pressing “Ctrl+Alt+T” button
  2. Go to the directory (use “cd /path/directory-name/so-on”) that contains file(s) and folder(s) you want to zipped
  3. Use “zip” command and specify output-file-name with the folder / directory name and/or the file(s) that you want to add to the archive separated by space
  4. The syntax for using the zip command as shown below:
    • Create a zip archive containing all the files in the current directory.
      zip [option] [output-file-name.zip] [*]

      Example: zip archive.zip *

    • Create a zip archive containing all the files in the current directory including the hidden files (files starting with a dot).
      zip [option] [output-file-name.zip] [.* *]

      Example: zip archive.zip .* *

    • Create a zip archive containing folder and multiple files in the current directory
      zip [option] [output-file-name.zip] [folder-name file1 file2 file3]

      Example: zip archive.zip Documents filename.txt image.jpg imaege.png

  5. The “.zip” extension after the “output-file-name” is optional as .zip is automatically added by default
  6. You can add multiple files and folder / directories in the same archive or output
  7. There could be several options to execute zip command
  8. Files and or folder will be added to the compressed output-file-name in the current directory
  9. Done, now you have zip archive

The zip program puts one or more compressed files into a single zip archive, along with information about the files (name, path, date, time of last modification, protection, and check information to verify file integrity). An entire directory structure can be packed into a zip archive with a single command.

UNZIP on Linux

unzip will list, test, or extract files from a ZIP archive, commonly found on MS-DOS systems. The default behavior (with no options) is to extract into the current directory (and subdirectories below it) all files from the specified ZIP archive. This is compatible with archives for MS-DOS, but in many cases the program options or default behaviors differ.

To unzip archived file via terminal on Linux:

  1. Open “Terminal” or by pressing “Ctrl+Alt+T” button
  2. Go to the directory (use “cd /path/directory-name/so-on”) that contains zip file that you want to extract
  3. Use “unzip” command and specify zip file in the working directory
  4. The syntax for using the unzip command as shown below:
    • extract zipped file in the current directory.
      unzip [option] zipped-file.zip [option]

      Example: unzip archive.zip

    • unzip a ZIP file to a new folder name you specified in the current directory (If the folder / directory doesn’t exist, it will create one).
      unzip archive.zip -d new-foldername

      Example: unzip archive.zip -d new-folder

    • unzip a ZIP file to a different directory (in below case to Documents directory).
      unzip zipped-file.zip -d /path/to-directory

      Example: unzip archive.zip -d /home/user/Documents

  5. By default, unzip display the names of all the files it’s extracting and a summary when the extraction is completed.
  6. There could be several options to unzip zipped file
  7. That’s it. Now you know how to unzip a file in Linux

Note: You don’t always have to go to the terminal if you are using desktop Linux. You can perform zip and unzip in Graphical User Interface.

License: CC-BY-SA Creative Commons License
☝️