How to Compress & Decompress a Folder in Command Line

To compress a folder using the command line, you can use various tools depending on the compression format you prefer. Here are a few examples:

  1. ZIP Compression:
  • Syntax: zip -r your_archive.zip folder_to_compress
  • Explanation:
    • zip: Command for creating a ZIP archive.
    • -r: Recursive flag to include all files and subdirectories within the specified folder.
    • your_archive.zip: Name of the resulting ZIP file.
    • folder_to_compress: Path to the folder you want to compress.
    Example:
   zip -r myarchive.zip myfolder
  1. GZIP Compression (TAR + GZIP):
  • Syntax: tar -czvf your_archive.tar.gz folder_to_compress
  • Explanation:
    • tar: Command for creating a TAR archive.
    • -c: Create a new archive.
    • -z: Use GZIP compression.
    • -v: Verbose mode to display progress.
    • -f: Specify the name of the resulting archive.
    • your_archive.tar.gz: Name of the resulting TAR GZIP file.
    • folder_to_compress: Path to the folder you want to compress.
    Example:
   tar -czvf myarchive.tar.gz myfolder
  1. TAR Compression:
  • Syntax: tar -cvf your_archive.tar folder_to_compress
  • Explanation:
    • tar: Command for creating a TAR archive.
    • -c: Create a new archive.
    • -v: Verbose mode to display progress.
    • -f: Specify the name of the resulting archive.
    • your_archive.tar: Name of the resulting TAR file.
    • folder_to_compress: Path to the folder you want to compress.
    Example:
   tar -cvf myarchive.tar myfolder
  1. RAR Compression:
  • Syntax: rar a your_archive.rar folder_to_compress
  • Explanation:
    • rar: Command for creating a RAR archive.
    • a: Archive mode to create a new archive.
    • your_archive.rar: Name of the resulting RAR file.
    • folder_to_compress: Path to the folder you want to compress.
    Example:
   rar a myarchive.rar myfolder
  1. 7z Compression:
  • Syntax: 7z a your_archive.7z folder_to_compress
  • Explanation:
    • 7z: Command for creating a 7z archive.
    • a: Archive mode to create a new archive.
    • your_archive.7z: Name of the resulting 7z file.
    • folder_to_compress: Path to the folder you want to compress.
    Example:
   7z a myarchive.7z myfolder

Remember to replace your_archive with the desired name for the resulting compressed file and folder_to_compress with the actual path to the folder you want to compress.

To decompress or extract a compressed folder or file in the command line, you can use various commands depending on the compression format used. Here are the commands for different compression formats:

  1. ZIP Decompression:
  • Syntax: unzip your_archive.zip
  • Explanation:
    • unzip: Command for extracting ZIP archives.
    • your_archive.zip: Name of the ZIP file you want to extract.
    Example:
   unzip myarchive.zip
  1. GZIP Decompression (TAR + GZIP):
  • Syntax: tar -xzvf your_archive.tar.gz
  • Explanation:
    • tar: Command for manipulating TAR archives.
    • -x: Extract files from the archive.
    • -z: Use GZIP decompression.
    • -v: Verbose mode to display progress.
    • -f: Specify the name of the archive.
    • your_archive.tar.gz: Name of the TAR GZIP file you want to extract.
    Example:
   tar -xzvf myarchive.tar.gz
  1. TAR Decompression:
  • Syntax: tar -xvf your_archive.tar
  • Explanation:
    • tar: Command for manipulating TAR archives.
    • -x: Extract files from the archive.
    • -v: Verbose mode to display progress.
    • -f: Specify the name of the archive.
    • your_archive.tar: Name of the TAR file you want to extract.
    Example:
   tar -xvf myarchive.tar
  1. RAR Decompression:
  • Syntax: unrar x your_archive.rar
  • Explanation:
    • unrar: Command for extracting RAR archives.
    • x: Extract files from the archive.
    • your_archive.rar: Name of the RAR file you want to extract.
    Example:
   unrar x myarchive.rar
  1. 7z Decompression:
  • Syntax: 7z x your_archive.7z
  • Explanation:
    • 7z: Command for extracting 7z archives.
    • x: Extract files from the archive.
    • your_archive.7z: Name of the 7z file you want to extract.
    Example:
   7z x myarchive.7z

Remember to replace your_archive with the actual name of the compressed file you want to extract. The extracted files will be placed in the current directory unless specified otherwise.

Don't Miss Out! Subscribe to Read Our Latest Blogs.

Subscription form (#5)

If you found this blog helpful, share it on social media.

Leave a Comment

Pin It on Pinterest

Scroll to Top