Zip & Unzip

Last modified: 2023-03-28

Archive

Zip is a command-line tool used for creating and manipulating compressed archive files in Unix, Linux, and other Unix-like operating systems.

Compress

zip example example1.txt example2.txt

Decompress

unzip example.zip
# Specify the directory to decompress
unzip example.zip -d ./example

Unzip with Python

Also we can decompress an archived file using Python script.

import zipfile

filename = "./sample.zip"
extdir = "./"
password = "password123"

with zipfile.ZipFile(filename, 'r') as zp:
    try:
        zp.extractall(path=extdir, pwd=password.encode('utf-8'))
    except RuntimeError as e:
        print(e)