{"id":246434,"date":"2025-12-08T10:26:59","date_gmt":"2025-12-08T10:26:59","guid":{"rendered":"https:\/\/www.bluehost.com\/blog\/?p=246434"},"modified":"2025-12-09T07:39:00","modified_gmt":"2025-12-09T07:39:00","slug":"compress-decompress-files-via-cli","status":"publish","type":"post","link":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/","title":{"rendered":"How to Compress and Decompress Files Using Zip File Command Line\u00a0"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\" id=\"h-key-highlights-nbsp-nbsp\"><strong>Key highlights&nbsp;<\/strong>&nbsp;<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Learn to use the zip file command line effectively on Linux, macOS\u00a0and\u00a0Windows.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand how to create\u00a0zip\u00a0file from folder command line using different utilities.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Discover commands for compressing and decompressing .tar, .gz, .bz2\u00a0and\u00a0.rar\u00a0archives.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Explore the syntax for viewing,\u00a0extracting\u00a0and\u00a0combining compressed files.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Practice practical examples of file compression via SSH,\u00a0PowerShell\u00a0and\u00a0Linux terminal.\u00a0<\/li>\n<\/ul>\n\n\n\n<p>Managing files through the command line interface (CLI), including understanding the zip file format, is a core skill for developers, system&nbsp;administrators&nbsp;and&nbsp;advanced users across different operating systems. Whether&nbsp;you\u2019re&nbsp;saving disk space, transferring large&nbsp;datasets&nbsp;or&nbsp;creating backups, file compression makes your workflow more efficient.&nbsp;&nbsp;<\/p>\n\n\n\n<p>In this guide,&nbsp;we\u2019ll&nbsp;explore how to compress and decompress files using various CLI commands, including zip,&nbsp;gzip,&nbsp;bzip2, tar&nbsp;and&nbsp;rar.&nbsp;We\u2019ll&nbsp;also explain the syntax,&nbsp;examples&nbsp;and&nbsp;useful options for each command.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-understanding-the-basics-and-syntax-nbsp-nbsp\"><strong>Understanding the basics and syntax&nbsp;<\/strong>&nbsp;<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-is-file-compression-nbsp-nbsp\"><strong>What is file compression?&nbsp;<\/strong>&nbsp;<\/h3>\n\n\n\n<p>File compression reduces file size by encoding data more efficiently, such as when you choose to&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/ZIP_%28file_format%29?\" target=\"_blank\" rel=\"noreferrer noopener\">zip folder<\/a><s>&nbsp;<\/s>. This helps save disk space and makes transferring or archiving files faster. Compression tools like zip,&nbsp;gzip&nbsp;and&nbsp;bzip2 are available across major operating systems, including Windows, macOS&nbsp;and&nbsp;Linux.&nbsp;<\/p>\n\n\n\n<p>A zip archive can bundle multiple files or directories into a single file, using formats such as .zip, .tar.gz, .bz2&nbsp;or&nbsp;.rar. An archive file is a single file that&nbsp;contains&nbsp;one or more compressed files or directories, often created using commands like tar or&nbsp;gzip&nbsp;and&nbsp;can use formats like .tar, .tar.gz&nbsp;or&nbsp;.tgz. These formats&nbsp;maintain&nbsp;the directory structure, making extraction easier later.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-basic-syntax-for-compression-and-decompression-commands-nbsp-nbsp\"><strong>Basic syntax for compression and decompression commands&nbsp;<\/strong>&nbsp;<\/h3>\n\n\n\n<p>The general syntax for compression and decompression is:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>command &#91;options] &#91;archive-name] &#91;files\/directories]\u00a0<\/code><\/pre>\n\n\n\n<p>In this syntax, &#8216;[files\/directories]&#8217;&nbsp;represents&nbsp;the input that you want to compress or decompress.&nbsp;<\/p>\n\n\n\n<p>To create a zip archive, use the following command:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zip -r my_archive.zip\u00a0my_folder\/\u00a0<\/code><\/pre>\n\n\n\n<p>Here, -r&nbsp;recursively includes all files and subdirectories. The zip file command line provides flexibility to compress and organize data efficiently.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-compressing-and-decompressing-files-via-ssh-nbsp-nbsp\"><strong>Compressing and decompressing files via SSH&nbsp;<\/strong>&nbsp;<\/h2>\n\n\n\n<p>When managing remote servers, you can compress and decompress files via&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Secure_Shell?\" target=\"_blank\" rel=\"noreferrer noopener\">SSH<\/a>. You can perform these operations remotely to streamline server management. This helps transfer archives faster and use less bandwidth. To ensure the integrity of a zip file before transferring, use the -t (test)&nbsp;option&nbsp;to check if the file is corrupted without extracting its contents.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh username@server-ip\u00a0\nzip -r backup.zip \/var\/www\/html\/\u00a0<\/code><\/pre>\n\n\n\n<p>These commands can also be run from the command prompt on Windows systems&nbsp;or&nbsp;from a terminal on Linux\/macOS.&nbsp;<\/p>\n\n\n\n<p>Then use&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Secure_copy_protocol?\" target=\"_blank\" rel=\"noreferrer noopener\">Secure copy protocol (SCP)<\/a>&nbsp;to copy the archive back to your local machine:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp\u00a0username@server-ip:\/var\/www\/html\/backup.zip\u00a0~\/Downloads\/\u00a0<\/code><\/pre>\n\n\n\n<p>The same process applies when decompressing using SSH. For instance:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh\u00a0username@server-ip\u00a0'unzip backup.zip -d \/var\/www\/html\/'\u00a0<\/code><\/pre>\n\n\n\n<p>Files can be extracted to a specific directory using the -d&nbsp;option,&nbsp;and&nbsp;the extracted files will&nbsp;maintain&nbsp;their original directory structure unless specified otherwise.&nbsp;<\/p>\n\n\n\n<p>When managing remote servers, you can compress and decompress files via SSH. If you\u00a0host with\u00a0Bluehost, SSH access is\u00a0built in\u00a0across\u00a0<a href=\"https:\/\/www.bluehost.com\/web-hosting\">Shared<\/a>,\u00a0<a href=\"https:\/\/www.bluehost.com\/vps-hosting\">VPS<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.bluehost.com\/dedicated-hosting\">Dedicated<\/a>\u00a0plans.\u00a0You can enable it from your\u00a0<a href=\"https:\/\/www.bluehost.com\/blog\/cpanel-overview\/\">cPanel<\/a>\u00a0(under &#8216;<em>Security&#8217; \u2192 &#8216;SSH Access&#8217;<\/em>) or, for VPS and Dedicated servers, directly through WHM.\u00a0\u00a0<\/p>\n\n\n\n<p>Bluehost provides secure port-22 connections and a built-in Web Console for&nbsp;SSH&nbsp;in certain plans,&nbsp;letting you manage files or run compression commands right from your dashboard.&nbsp;Shared hosting provides jailed SSH; VPS\/Dedicated plans provide root-level control.&nbsp;<\/p>\n\n\n\n<svg version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" xmlns:xlink=\"http:\/\/www.w3.org\/1999\/xlink\" viewBox=\"0 0 1001 300\"> \n\n  <image width=\"1001\" height=\"300\" xlink:href=\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/03\/Hosting-2.png\"><\/image> <a xlink:href=\"https:\/\/www.bluehost.com\/web-hosting \"> \n\n    <rect x=\"84\" y=\"180\" fill=\"#fff\" opacity=\"0\" width=\"187\" height=\"63\"><\/rect> \n\n  <\/a> \n\n<\/svg> \n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-working-with-different-file-types-nbsp-nbsp\"><strong>Working with different file types&nbsp;<\/strong>&nbsp;<\/h2>\n\n\n\n<p>Let\u2019s&nbsp;look at the different file types and their commands:&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Task<\/strong>&nbsp;<\/td><td><strong>Command<\/strong>&nbsp;<\/td><td><strong>Works On<\/strong>&nbsp;<\/td><\/tr><tr><td>Zip folder&nbsp;<\/td><td>zip -r archive.zip folder\/&nbsp;<\/td><td>Linux\/macOS&nbsp;<\/td><\/tr><tr><td>Unzip file&nbsp;<\/td><td>unzip archive.zip&nbsp;<\/td><td>Linux\/macOS&nbsp;<\/td><\/tr><tr><td>Gzip&nbsp;file&nbsp;<\/td><td>gzip&nbsp;file.txt&nbsp;<\/td><td>Linux\/macOS&nbsp;<\/td><\/tr><tr><td>Tar +&nbsp;gzip&nbsp;<\/td><td>tar -czf&nbsp;archive.tar.gz folder\/&nbsp;<\/td><td>Linux\/macOS&nbsp;<\/td><\/tr><tr><td>PowerShell zip&nbsp;<\/td><td>Compress-Archive -Path folder -DestinationPath&nbsp;archive.zip&nbsp;<\/td><td>Windows&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-using-the-zip-and-unzip-commands-nbsp-nbsp\"><strong>1. Using the zip and unzip commands&nbsp;<\/strong>&nbsp;<\/h3>\n\n\n\n<p>Here&nbsp;are&nbsp;the different commands using zip and unzip:&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-compressing-files-and-directories\"><strong>Compressing files and directories<\/strong>\u00a0<\/h4>\n\n\n\n<p>To create zip file command line:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zip -r archive.zip\u00a0directory_name\/\u00a0<\/code><\/pre>\n\n\n\n<p>This command creates a .zip archive&nbsp;containing&nbsp;the entire folder and its contents.&nbsp;It\u2019s&nbsp;ideal for backing up websites or project files. You can automate this process on Windows by placing the command in a bat file, allowing you to quickly zip folders with a double-click.&nbsp;<\/p>\n\n\n\n<p><s>&nbsp;<\/s>Alternatively, you can use VBS (VBScript) scripts to automate ZIP file creation and compression tasks on Windows.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-decompressing-files\"><strong>Decompressing files<\/strong>\u00a0<\/h4>\n\n\n\n<p>To extract zip file Linux command line: Use the unzip command followed by the file name. If you want to extract all files directly into the destination directory without preserving the internal folder structure, use the -j (junk paths)&nbsp;option.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>unzip archive.zip\u00a0<\/code><\/pre>\n\n\n\n<p>This command will unzip the file named archive.zip in your current directory, extracting its contents. To prevent overwriting files that already exist, use the -n&nbsp;option&nbsp;during extraction.&nbsp;<\/p>\n\n\n\n<p>For Ubuntu users, install the unzip utility if&nbsp;it\u2019s&nbsp;missing:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo\u00a0apt install unzip\u00a0<\/code><\/pre>\n\n\n\n<p>Then you can use&nbsp;the ubuntu&nbsp;unzip zip file command line to extract files efficiently.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-viewing-contents-without-extraction\"><strong>Viewing contents without extraction<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>unzip -l archive.zip\u00a0<\/code><\/pre>\n\n\n\n<p>This command lists all files inside the zip archive without decompressing them. Use it to view or list the contents of a ZIP file before extraction. The -l&nbsp;option&nbsp;can be used to achieve this, providing a detailed list of the archive&#8217;s contents.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-useful-zip-options-and-examples\"><strong>Useful zip options and examples<\/strong>\u00a0<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-P password<\/strong>: Create a password protected archive.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-x filename<\/strong>: Exclude specific files.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-d path<\/strong>: Extract files to a specific directory.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-r:<\/strong>\u00a0Recursively zip all the files inside directories.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-z:<\/strong>\u00a0Add a comment to the ZIP archive for documentation or clarity.\u00a0<\/li>\n<\/ul>\n\n\n\n<p>Example:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zip -r project.zip\u00a0project_folder\/ -x \"*.log\"\u00a0<\/code><\/pre>\n\n\n\n<p>This excludes log files from being added to the archive. The resulting archive will&nbsp;contain&nbsp;only the zipped files you specified, excluding any log files.&nbsp;<\/p>\n\n\n\n<p>To add a comment to your ZIP archive, use the -z&nbsp;option:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zip -r project.zip\u00a0project_folder\/ -z\u00a0<\/code><\/pre>\n\n\n\n<p>This will prompt you to enter a comment, which can help document the contents or purpose of the archive.&nbsp;<\/p>\n\n\n\n<p>For Windows&nbsp;10 and 11&nbsp;users, you can also use the&nbsp;Windows zip file command line;&nbsp;the tar command can be used to compress files into ZIP format using the -a&nbsp;option, providing a native solution for handling ZIP files.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Compress-Archive -Path C:\\folder -DestinationPath\u00a0C:\\archive.zip\u00a0<\/code><\/pre>\n\n\n\n<p>This PowerShell command is a modern&nbsp;powershell&nbsp;compress archive equivalent&nbsp;of&nbsp;the zip command.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-using-nbsp-gzip-nbsp-and-nbsp-gunzip-nbsp-commands-nbsp-nbsp\"><strong>2. Using&nbsp;gzip&nbsp;and&nbsp;gunzip&nbsp;commands&nbsp;<\/strong>&nbsp;<\/h3>\n\n\n\n<p>Here&nbsp;are&nbsp;the different commands using&nbsp;gzip&nbsp;and&nbsp;gunzip:&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-compressing-files\"><strong>Compressing files<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>gzip&nbsp;filename.txt&nbsp;<\/code><\/pre>\n\n\n\n<p>This replaces filename.txt with a smaller filename.txt.gz file.&nbsp;<\/p>\n\n\n\n<p>To compress a file in Linux command line, you can also specify multiple files:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gzip&nbsp;file1.txt file2.txt file3.txt&nbsp;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-decompressing-files-0\"><strong>Decompressing files<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>gunzip&nbsp;filename.txt.gz&nbsp;<\/code><\/pre>\n\n\n\n<p>This restores the original file&nbsp;&#8211;&nbsp;a simple way&nbsp;to&nbsp;decompress&nbsp;file&nbsp;Linux command line.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-viewing-contents-without-decompression\"><strong>Viewing contents without decompression<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>zcat&nbsp;filename.txt.gz&nbsp;<\/code><\/pre>\n\n\n\n<p>Displays the content of compressed files without extraction.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-setting-compression-levels\"><strong>Setting compression levels<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>gzip&nbsp;-1 file.txt&nbsp;&nbsp; # Fastest compression&nbsp;<br>gzip -9 file.txt&nbsp;&nbsp; # Best compression&nbsp;<\/code><\/pre>\n\n\n\n<p>Choose a level based on your needs,&nbsp;faster&nbsp;compression&nbsp;or smaller file size.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-concatenating-multiple-compressed-files\"><strong>Concatenating multiple compressed files<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>cat file1.gz file2.gz &gt; combined.gz&nbsp;<\/code><\/pre>\n\n\n\n<p>Combines several compressed files into a single archive.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-using-bzip2-and-bunzip2-commands-nbsp-nbsp\"><strong>3. Using bzip2 and bunzip2 commands&nbsp;<\/strong>&nbsp;<\/h3>\n\n\n\n<p>Here&nbsp;are&nbsp;the different commands using bzip2 and bunzip2:&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-compressing-and-decompressing-files\"><strong>Compressing and decompressing files<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>bzip2 filename.txt&nbsp;<br>bunzip2 filename.txt.bz2&nbsp;<\/code><\/pre>\n\n\n\n<p>These commands compress and decompress files using the&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Bzip2?\" target=\"_blank\" rel=\"noreferrer noopener\">bzip2<\/a>&nbsp;algorithm, known for its higher compression ratio compared to&nbsp;gzip.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-comparing-compression-with-gzip\"><strong>Comparing compression with\u00a0gzip<\/strong>\u00a0<\/h4>\n\n\n\n<p>While bzip2 achieves better compression,&nbsp;it\u2019s&nbsp;slower than&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Gzip?\" target=\"_blank\" rel=\"noreferrer noopener\">gzip<\/a>.&nbsp;Use&nbsp;bzip2 when minimizing file size is more critical than speed.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-useful-command-line-options\"><strong>Useful command line options<\/strong>\u00a0<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-k: Keep existing files after compression.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-v: Show detailed progress.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-d: Decompress files explicitly.\u00a0<\/li>\n<\/ul>\n\n\n\n<p>Example:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bzip2 -kv&nbsp;largefile.txt&nbsp;<\/code><\/pre>\n\n\n\n<p>This command compresses while keeping the original single file.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-using-tar-for-archiving-and-compression-nbsp-nbsp\"><strong>4. Using tar for archiving and compression&nbsp;<\/strong>&nbsp;<\/h3>\n\n\n\n<p>Here&nbsp;are&nbsp;the different commands using tar:&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-creating-tar-archives\"><strong>Creating .tar archives<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -cvf\u00a0archive.tar directory\/\u00a0<\/code><\/pre>\n\n\n\n<p>This bundles files without compression, creating a tar file.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-extracting-tar-archives\"><strong>Extracting .tar archives<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xvf&nbsp;archive.tar&nbsp;<\/code><\/pre>\n\n\n\n<p>The command extracts the contents to the current directory.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-working-with-tar-gz-files\"><strong>Working\u00a0with .tar.gz files<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -czvf&nbsp;archive.tar.gz folder\/&nbsp;<\/code><\/pre>\n\n\n\n<p>To extract:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xzvf&nbsp;archive.tar.gz&nbsp;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-working-with-tar-bz2-files\"><strong>Working\u00a0with .tar.bz2 files<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -cjvf&nbsp;archive.tar.bz2 folder\/&nbsp;<\/code><\/pre>\n\n\n\n<p>To extract:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xjvf&nbsp;archive.tar.bz2&nbsp;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-common-tar-options-and-shortcuts\"><strong>Common tar options and shortcuts<\/strong>\u00a0<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-c: Create archive\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-x: Extract files\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-v: Show progress\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-f: Specify file name\u00a0<\/li>\n<\/ul>\n\n\n\n<p>Use tar to back up program files or package existing files before deployment. The tar command is widely used for backups and software packaging across operating systems.&nbsp;&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-5-working-with-rar-and-unrar-files\"><strong>5. Working with\u00a0rar\u00a0and\u00a0unrar\u00a0files\u00a0\u00a0<\/strong><\/h3>\n\n\n\n<p>Here are the different commands using&nbsp;rar&nbsp;and&nbsp;unrar:&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-installing-rar-unrar\"><strong>Installing\u00a0rar\/unrar<\/strong>\u00a0<\/h4>\n\n\n\n<p>For Linux or Ubuntu:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo&nbsp;apt install&nbsp;rar&nbsp;unrar&nbsp;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-compressing-files-0\"><strong>Compressing files<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>rar&nbsp;a&nbsp;archive.rar&nbsp;folder\/&nbsp;<\/code><\/pre>\n\n\n\n<p>Creates a .rar&nbsp;archive.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-decompressing-files-1\"><strong>Decompressing files<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>unrar&nbsp;x&nbsp;archive.rar&nbsp;<\/code><\/pre>\n\n\n\n<p>This extracts and&nbsp;maintains&nbsp;the directory structure.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-exploring-useful-command-line-options\"><strong>Exploring useful command line options<\/strong>\u00a0<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>x: Extract with path\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>e: Extract without preserving directories\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>t: Test archive integrity\u00a0<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-specifying-output-locations\"><strong>Specifying output locations<\/strong>\u00a0<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>unrar&nbsp;x&nbsp;archive.rar&nbsp;\/path\/to\/output\/&nbsp;<\/code><\/pre>\n\n\n\n<p>This extracts files to a specified location.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-preserving-permissions-and-directory-structures\"><strong>Preserving permissions and directory structures<\/strong>\u00a0<\/h4>\n\n\n\n<p>RAR automatically preserves file permissions when&nbsp;extracting&nbsp;unless manually overridden.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-combining-commands-for-efficiency\"><strong>Combining commands for efficiency<\/strong>\u00a0<\/h4>\n\n\n\n<p>You can combine commands to compress and back up files quickly:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -czf&nbsp;backup.tar.gz \/home\/user &amp;&amp;&nbsp;gzip&nbsp;backup.tar.gz&nbsp;<\/code><\/pre>\n\n\n\n<p>This creates a&nbsp;compressed .tar.gz backup in one go.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-learning-more-about-commands-nbsp-nbsp\"><strong>Learning more about commands&nbsp;<\/strong>&nbsp;<\/h2>\n\n\n\n<p>There are many more helpful commands that will surely come in&nbsp;handy,&nbsp;let\u2019s&nbsp;look at them in detail.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-man-command-nbsp\"><strong>Using the man command<\/strong>&nbsp;<\/h3>\n\n\n\n<p>To view command documentation:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>man&nbsp;zip&nbsp;<br>man tar&nbsp;<\/code><\/pre>\n\n\n\n<p>This displays the manual page for each command with syntax,&nbsp;options&nbsp;and&nbsp;usage&nbsp;examples.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-checking-help-options-h-help-nbsp\"><strong>Checking help options (-h, &#8211;help)<\/strong>&nbsp;<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>zip --help&nbsp;<br>unzip -h&nbsp;<br>tar --help&nbsp;<\/code><\/pre>\n\n\n\n<p>Using help flags shows quick references and command examples for everyday use.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-final-thoughts-nbsp-nbsp\"><strong>Final thoughts&nbsp;<\/strong>&nbsp;<\/h2>\n\n\n\n<p>Learning how to use the zip file command line on systems like&nbsp;Windows&nbsp;helps you manage data more efficiently. Whether&nbsp;you\u2019re&nbsp;using a&nbsp;Windows machine, macOS terminal&nbsp;or&nbsp;Linux system, understanding compression saves time and space. You can create&nbsp;a&nbsp;zip&nbsp;file&nbsp;from folder command line, extract&nbsp;archives&nbsp;or&nbsp;automate backup processes using shell scripts.&nbsp;<\/p>\n\n\n\n<p>Mastering commands like zip,&nbsp;gzip, bzip2, tar&nbsp;and&nbsp;rar&nbsp;allow&nbsp;you to manage compressed files confidently. From reducing file size to transferring projects between servers, CLI compression&nbsp;remains&nbsp;a must-have skill across all operating systems.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Looking for hosting with secure SSH built in? We at Bluehost include SSH access by\u00a0default-\u00a0ideal for safe, scripted backups and restores.\u00a0Explore\u00a0<a href=\"https:\/\/www.bluehost.com\/pricing\">Bluehost web hosting plans<\/a>\u00a0today.\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faqs-nbsp-nbsp\"><strong>FAQs&nbsp;<\/strong>&nbsp;<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1765189297962\"><strong class=\"schema-faq-question\"><strong>How to create\u00a0zip\u00a0file from\u00a0folder\u00a0command line in Windows?<\/strong>\u00a0<\/strong> <p class=\"schema-faq-answer\">In Windows, you can create a ZIP file from a folder using PowerShell. Specify the folder you want to compress and choose a destination ZIP file name. This method is the equivalent of using the PowerShell Compress-Archive command for creating ZIP archives.\u00a0This question shows research effort in\u00a0identifying\u00a0efficient command line zip file methods.\u00a0<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1765189310544\"><strong class=\"schema-faq-question\"><strong>How to unzip a zip file in\u00a0the Linux\u00a0command line?<\/strong>\u00a0<\/strong> <p class=\"schema-faq-answer\">In Linux, you can extract a ZIP file by using the unzip utility. Install the utility via your package manager if\u00a0it\u2019s\u00a0not already\u00a0installed\u00a0and\u00a0then run the command to decompress the contents into the current directory.\u00a0<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1765189326166\"><strong class=\"schema-faq-question\"><strong>How to compress a file in\u00a0Linux\u00a0command line?<\/strong>\u00a0<\/strong> <p class=\"schema-faq-answer\">To compress a file in Linux, you can use the\u00a0gzip\u00a0command. The\u00a0gzip\u00a0replaces the original file with a compressed version that ends with the .gz\u00a0extension.\u00a0<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1765189333762\"><strong class=\"schema-faq-question\"><strong>How to decompress\u00a0file\u00a0Linux command line?<\/strong>\u00a0<\/strong> <p class=\"schema-faq-answer\">You can decompress files using the\u00a0gunzip\u00a0command. The\u00a0gunzip\u00a0restores the original file by removing the .gz\u00a0extension and expanding its contents.\u00a0<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1765189347627\"><strong class=\"schema-faq-question\"><strong>How to unzip\u00a0zip\u00a0file command line on macOS?<\/strong>\u00a0<\/strong> <p class=\"schema-faq-answer\">On macOS, you can extract ZIP files directly from the terminal by typing the unzip command followed by the file name. Alternatively, you can also open ZIP files through Finder if you prefer a graphical interface.\u00a0<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Quickly learn CLI commands to compress and decompress files with zip, gzip, bzip2 and tar. <\/p>\n","protected":false},"author":152,"featured_media":259754,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_yoast_wpseo_title":"Zip File Command Line: How to Compress & Decompress Files","_yoast_wpseo_metadesc":"Master zip file command line tools like gzip, bzip2, and tar. Learn to compress and extract files on Linux, macOS, and Windows.","inline_featured_image":false,"footnotes":""},"categories":[9],"tags":[],"ppma_author":[948],"class_list":["post-246434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.1 (Yoast SEO v27.1.1) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Zip File Command Line: How to Compress &amp; Decompress Files<\/title>\n<meta name=\"description\" content=\"Master zip file command line tools like gzip, bzip2, and tar. Learn to compress and extract files on Linux, macOS, and Windows.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/posts\/246434\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Compress and Decompress Files Using Zip File Command Line\u00a0\" \/>\n<meta property=\"og:description\" content=\"Master zip file command line tools like gzip, bzip2, and tar. Learn to compress and extract files on Linux, macOS, and Windows.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/\" \/>\n<meta property=\"og:site_name\" content=\"Bluehost Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/bluehost\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-12-08T10:26:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-09T07:39:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Charrvi Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bluehost\" \/>\n<meta name=\"twitter:site\" content=\"@bluehost\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Charrvi Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/\"},\"author\":{\"name\":\"Charrvi Singh\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/#\/schema\/person\/0dd00ba2d4fe091c8ca8ade8b5d5d4ce\"},\"headline\":\"How to Compress and Decompress Files Using Zip File Command Line\u00a0\",\"datePublished\":\"2025-12-08T10:26:59+00:00\",\"dateModified\":\"2025-12-09T07:39:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/\"},\"wordCount\":2081,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png\",\"articleSection\":[\"General\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/\",\"url\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/\",\"name\":\"Zip File Command Line: How to Compress & Decompress Files\",\"isPartOf\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png\",\"datePublished\":\"2025-12-08T10:26:59+00:00\",\"dateModified\":\"2025-12-09T07:39:00+00:00\",\"description\":\"Master zip file command line tools like gzip, bzip2, and tar. Learn to compress and extract files on Linux, macOS, and Windows.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189297962\"},{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189310544\"},{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189326166\"},{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189333762\"},{\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189347627\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#primaryimage\",\"url\":\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png\",\"contentUrl\":\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png\",\"width\":1200,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.bluehost.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"General\",\"item\":\"https:\/\/www.bluehost.com\/blog\/category\/general\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Compress and Decompress Files Using Zip File Command Line\u00a0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/#website\",\"url\":\"https:\/\/www.bluehost.com\/blog\/\",\"name\":\"Bluehost\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.bluehost.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/#organization\",\"name\":\"Bluehost\",\"url\":\"https:\/\/www.bluehost.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2023\/08\/bluehost-logo.svg\",\"contentUrl\":\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2023\/08\/bluehost-logo.svg\",\"width\":136,\"height\":24,\"caption\":\"Bluehost\"},\"image\":{\"@id\":\"https:\/\/www.bluehost.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/bluehost\/\",\"https:\/\/x.com\/bluehost\",\"https:\/\/www.linkedin.com\/company\/bluehost-com\/\",\"https:\/\/www.youtube.com\/user\/bluehost\",\"https:\/\/en.wikipedia.org\/wiki\/Bluehost\"],\"description\":\"Bluehost is a leading web hosting provider empowering millions of websites worldwide. \\u2028Discover how Bluehost's expertise, reliability, and innovation can help you achieve your online goals.\",\"telephone\":\"+1-888-401-4678\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/#\/schema\/person\/0dd00ba2d4fe091c8ca8ade8b5d5d4ce\",\"name\":\"Charrvi Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/#\/schema\/person\/image\/c446c4008d82f101ae13175515e45db7\",\"url\":\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2024\/11\/Media-e1732870672924.jpg\",\"contentUrl\":\"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2024\/11\/Media-e1732870672924.jpg\",\"caption\":\"Charrvi Singh\"},\"description\":\"I\u2019m a published author, learning every day how words can make ideas clearer and connections stronger. Beyond work, I enjoy exploring new perspectives and finding inspiration in the small details of life.\",\"url\":\"https:\/\/www.bluehost.com\/blog\/author\/charrvi-singh\/\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189297962\",\"position\":1,\"url\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189297962\",\"name\":\"How to create\u00a0zip\u00a0file from\u00a0folder\u00a0command line in Windows?\u00a0\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"In Windows, you can create a ZIP file from a folder using PowerShell. Specify the folder you want to compress and choose a destination ZIP file name. This method is the equivalent of using the PowerShell Compress-Archive command for creating ZIP archives.\u00a0This question shows research effort in\u00a0identifying\u00a0efficient command line zip file methods.\u00a0\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189310544\",\"position\":2,\"url\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189310544\",\"name\":\"How to unzip a zip file in\u00a0the Linux\u00a0command line?\u00a0\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"In Linux, you can extract a ZIP file by using the unzip utility. Install the utility via your package manager if\u00a0it\u2019s\u00a0not already\u00a0installed\u00a0and\u00a0then run the command to decompress the contents into the current directory.\u00a0\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189326166\",\"position\":3,\"url\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189326166\",\"name\":\"How to compress a file in\u00a0Linux\u00a0command line?\u00a0\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"To compress a file in Linux, you can use the\u00a0gzip\u00a0command. The\u00a0gzip\u00a0replaces the original file with a compressed version that ends with the .gz\u00a0extension.\u00a0\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189333762\",\"position\":4,\"url\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189333762\",\"name\":\"How to decompress\u00a0file\u00a0Linux command line?\u00a0\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"You can decompress files using the\u00a0gunzip\u00a0command. The\u00a0gunzip\u00a0restores the original file by removing the .gz\u00a0extension and expanding its contents.\u00a0\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189347627\",\"position\":5,\"url\":\"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189347627\",\"name\":\"How to unzip\u00a0zip\u00a0file command line on macOS?\u00a0\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"On macOS, you can extract ZIP files directly from the terminal by typing the unzip command followed by the file name. Alternatively, you can also open ZIP files through Finder if you prefer a graphical interface.\u00a0\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Zip File Command Line: How to Compress & Decompress Files","description":"Master zip file command line tools like gzip, bzip2, and tar. Learn to compress and extract files on Linux, macOS, and Windows.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/posts\/246434\/","og_locale":"en_US","og_type":"article","og_title":"How to Compress and Decompress Files Using Zip File Command Line\u00a0","og_description":"Master zip file command line tools like gzip, bzip2, and tar. Learn to compress and extract files on Linux, macOS, and Windows.","og_url":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/","og_site_name":"Bluehost Blog","article_publisher":"https:\/\/www.facebook.com\/bluehost\/","article_published_time":"2025-12-08T10:26:59+00:00","article_modified_time":"2025-12-09T07:39:00+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png","type":"image\/png"}],"author":"Charrvi Singh","twitter_card":"summary_large_image","twitter_creator":"@bluehost","twitter_site":"@bluehost","twitter_misc":{"Written by":"Charrvi Singh","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#article","isPartOf":{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/"},"author":{"name":"Charrvi Singh","@id":"https:\/\/www.bluehost.com\/blog\/#\/schema\/person\/0dd00ba2d4fe091c8ca8ade8b5d5d4ce"},"headline":"How to Compress and Decompress Files Using Zip File Command Line\u00a0","datePublished":"2025-12-08T10:26:59+00:00","dateModified":"2025-12-09T07:39:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/"},"wordCount":2081,"commentCount":0,"publisher":{"@id":"https:\/\/www.bluehost.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png","articleSection":["General"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/","url":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/","name":"Zip File Command Line: How to Compress & Decompress Files","isPartOf":{"@id":"https:\/\/www.bluehost.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#primaryimage"},"image":{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png","datePublished":"2025-12-08T10:26:59+00:00","dateModified":"2025-12-09T07:39:00+00:00","description":"Master zip file command line tools like gzip, bzip2, and tar. Learn to compress and extract files on Linux, macOS, and Windows.","breadcrumb":{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189297962"},{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189310544"},{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189326166"},{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189333762"},{"@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189347627"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#primaryimage","url":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png","contentUrl":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2025\/12\/What-Is-A-500-Internal-Server-Error_-How-To-Fix-500-Internal-Server-Error-1.png","width":1200,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.bluehost.com\/blog\/"},{"@type":"ListItem","position":2,"name":"General","item":"https:\/\/www.bluehost.com\/blog\/category\/general\/"},{"@type":"ListItem","position":3,"name":"How to Compress and Decompress Files Using Zip File Command Line\u00a0"}]},{"@type":"WebSite","@id":"https:\/\/www.bluehost.com\/blog\/#website","url":"https:\/\/www.bluehost.com\/blog\/","name":"Bluehost","description":"","publisher":{"@id":"https:\/\/www.bluehost.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bluehost.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.bluehost.com\/blog\/#organization","name":"Bluehost","url":"https:\/\/www.bluehost.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bluehost.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2023\/08\/bluehost-logo.svg","contentUrl":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2023\/08\/bluehost-logo.svg","width":136,"height":24,"caption":"Bluehost"},"image":{"@id":"https:\/\/www.bluehost.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/bluehost\/","https:\/\/x.com\/bluehost","https:\/\/www.linkedin.com\/company\/bluehost-com\/","https:\/\/www.youtube.com\/user\/bluehost","https:\/\/en.wikipedia.org\/wiki\/Bluehost"],"description":"Bluehost is a leading web hosting provider empowering millions of websites worldwide. \u2028Discover how Bluehost's expertise, reliability, and innovation can help you achieve your online goals.","telephone":"+1-888-401-4678"},{"@type":"Person","@id":"https:\/\/www.bluehost.com\/blog\/#\/schema\/person\/0dd00ba2d4fe091c8ca8ade8b5d5d4ce","name":"Charrvi Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bluehost.com\/blog\/#\/schema\/person\/image\/c446c4008d82f101ae13175515e45db7","url":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2024\/11\/Media-e1732870672924.jpg","contentUrl":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2024\/11\/Media-e1732870672924.jpg","caption":"Charrvi Singh"},"description":"I\u2019m a published author, learning every day how words can make ideas clearer and connections stronger. Beyond work, I enjoy exploring new perspectives and finding inspiration in the small details of life.","url":"https:\/\/www.bluehost.com\/blog\/author\/charrvi-singh\/"},{"@type":"Question","@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189297962","position":1,"url":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189297962","name":"How to create\u00a0zip\u00a0file from\u00a0folder\u00a0command line in Windows?\u00a0","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"In Windows, you can create a ZIP file from a folder using PowerShell. Specify the folder you want to compress and choose a destination ZIP file name. This method is the equivalent of using the PowerShell Compress-Archive command for creating ZIP archives.\u00a0This question shows research effort in\u00a0identifying\u00a0efficient command line zip file methods.\u00a0","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189310544","position":2,"url":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189310544","name":"How to unzip a zip file in\u00a0the Linux\u00a0command line?\u00a0","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"In Linux, you can extract a ZIP file by using the unzip utility. Install the utility via your package manager if\u00a0it\u2019s\u00a0not already\u00a0installed\u00a0and\u00a0then run the command to decompress the contents into the current directory.\u00a0","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189326166","position":3,"url":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189326166","name":"How to compress a file in\u00a0Linux\u00a0command line?\u00a0","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"To compress a file in Linux, you can use the\u00a0gzip\u00a0command. The\u00a0gzip\u00a0replaces the original file with a compressed version that ends with the .gz\u00a0extension.\u00a0","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189333762","position":4,"url":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189333762","name":"How to decompress\u00a0file\u00a0Linux command line?\u00a0","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"You can decompress files using the\u00a0gunzip\u00a0command. The\u00a0gunzip\u00a0restores the original file by removing the .gz\u00a0extension and expanding its contents.\u00a0","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189347627","position":5,"url":"https:\/\/www.bluehost.com\/blog\/compress-decompress-files-via-cli\/#faq-question-1765189347627","name":"How to unzip\u00a0zip\u00a0file command line on macOS?\u00a0","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"On macOS, you can extract ZIP files directly from the terminal by typing the unzip command followed by the file name. Alternatively, you can also open ZIP files through Finder if you prefer a graphical interface.\u00a0","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"authors":[{"term_id":948,"user_id":152,"is_guest":0,"slug":"charrvi-singh","display_name":"Charrvi Singh","avatar_url":{"url":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2024\/11\/Media-e1732870672924.jpg","url2x":"https:\/\/www.bluehost.com\/blog\/wp-content\/uploads\/2024\/11\/Media-e1732870672924.jpg"},"0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":"","11":"","12":"","13":"","14":"","15":""}],"_links":{"self":[{"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/posts\/246434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/users\/152"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/comments?post=246434"}],"version-history":[{"count":4,"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/posts\/246434\/revisions"}],"predecessor-version":[{"id":259680,"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/posts\/246434\/revisions\/259680"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/media\/259754"}],"wp:attachment":[{"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/media?parent=246434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/categories?post=246434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/tags?post=246434"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.bluehost.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=246434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}