{"id":16583,"date":"2024-11-02T09:57:19","date_gmt":"2024-11-02T09:57:19","guid":{"rendered":"https:\/\/truehost.com\/support\/?post_type=docs&#038;p=16583"},"modified":"2024-11-02T09:57:50","modified_gmt":"2024-11-02T09:57:50","password":"","slug":"how-to-compress-and-decompress-files-using-tar-and-gzip","status":"publish","type":"docs","link":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/","title":{"rendered":"How to Compress and Decompress Files Using tar and gzip"},"content":{"rendered":"\n<p>Compressing and decompressing files is essential for saving disk space and transferring files efficiently. In Linux, the <code>tar<\/code> and <code>gzip<\/code> commands are commonly used for these purposes. Below is a guide on how to use these tools for compressing and decompressing files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What are tar and gzip?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>tar<\/strong>: The <code>tar<\/code> command (short for &#8220;tape archive&#8221;) is used to create, maintain, modify, or extract files from an archive file. It groups multiple files into a single file, often referred to as a tarball (typically with a <code>.tar<\/code> extension).<\/li>\n\n\n\n<li><strong>gzip<\/strong>: The <code>gzip<\/code> command is used to compress files, reducing their size for storage or transfer. It typically adds a <code>.gz<\/code> extension to the compressed files.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Installing tar and gzip<\/h3>\n\n\n\n<p>Most Linux distributions come with <code>tar<\/code> and <code>gzip<\/code> pre-installed. You can verify their availability by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar --version<br>gzip --version<\/code><\/pre>\n\n\n\n<p>If they are not installed, you can install them using your package manager.<\/p>\n\n\n\n<p>On Debian\/Ubuntu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<br>sudo apt install tar gzip<\/code><\/pre>\n\n\n\n<p>On RHEL\/CentOS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install tar gzip<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How to Compress Files with tar and gzip<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Creating a tar.gz Archive<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To compress files and directories into a single <code>.tar.gz<\/code> file, you can use the <code>tar<\/code> command with the <code>-z<\/code> option for gzip compression. The general syntax is:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -czvf archive_name.tar.gz file1 file2 directory1<\/code><\/pre>\n\n\n\n<p><strong>Options Explained<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>c<\/code>: Create a new archive.<\/li>\n\n\n\n<li><code>z<\/code>: Compress the archive with <code>gzip<\/code>.<\/li>\n\n\n\n<li><code>v<\/code>: Verbose mode (optional, shows progress in the terminal).<\/li>\n\n\n\n<li><code>f<\/code>: Specify the filename of the archive.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -czvf my_files.tar.gz file1.txt file2.txt my_directory\/<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This command creates a compressed file named <code>my_files.tar.gz<\/code> containing <code>file1.txt<\/code>, <code>file2.txt<\/code>, and the entire <code>my_directory<\/code>.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Creating a tar Archive (without gzip compression)<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want to create a <code>.tar<\/code> file without compression, omit the <code>-z<\/code> option:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -cvf archive_name.tar file1 file2 directory1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How to Decompress Files with tar and gzip<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Extracting a tar.gz Archive<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To decompress a <code>.tar.gz<\/code> file, use the following command:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xzvf archive_name.tar.gz<\/code><\/pre>\n\n\n\n<p><strong>Options Explained<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>x<\/code>: Extract files from the archive.<\/li>\n\n\n\n<li><code>z<\/code>: Uncompress the archive with <code>gzip<\/code>.<\/li>\n\n\n\n<li><code>v<\/code>: Verbose mode (optional).<\/li>\n\n\n\n<li><code>f<\/code>: Specify the filename of the archive.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xzvf my_files.tar.gz<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This command extracts the contents of <code>my_files.tar.gz<\/code> into the current directory.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Extracting a tar Archive (without gzip compression)<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To extract a <code>.tar<\/code> file without gzip compression, use:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xvf archive_name.tar<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Summary of Commands<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Compressing files and directories<\/strong>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -czvf archive_name.tar.gz file1 file2 directory1<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Extracting .tar.gz files<\/strong>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xzvf archive_name.tar.gz<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Compressing files without gzip<\/strong>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -cvf archive_name.tar file1 file2 directory1<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Extracting .tar files<\/strong>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xvf archive_name.tar<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Author&#8217;s Final Word<\/h3>\n\n\n\n<p>Using <code>tar<\/code> and <code>gzip<\/code>, you can efficiently compress and decompress files on Linux. This guide provides a basic overview of how to use these commands for file archiving and compression, allowing you to save disk space and streamline file transfers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Compressing and decompressing files is essential for saving disk space and transferring files efficiently. In Linux, the tar and gzip commands are commonly used for these purposes. Below is a guide on how to use these tools for compressing and decompressing files. What are tar and gzip? Installing tar and gzip Most Linux distributions come [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_eb_attr":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_category":[1820,1824,1879,2128],"doc_tag":[],"class_list":["post-16583","docs","type-docs","status-publish","hentry","doc_category-cloud-servers-in-kenya","doc_category-dedicated-servers","doc_category-servers","doc_category-vps-servers"],"year_month":"2026-06","word_count":494,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"Eugene","author_nicename":"eugene","author_url":"https:\/\/www.truehost.com\/support\/author\/eugene\/"},"doc_category_info":[{"term_name":"Cloud servers in Kenya","term_url":"https:\/\/www.truehost.com\/support\/docs-category\/cloud-servers-in-kenya\/"},{"term_name":"dedicated servers","term_url":"https:\/\/www.truehost.com\/support\/docs-category\/dedicated-servers\/"},{"term_name":"Servers","term_url":"https:\/\/www.truehost.com\/support\/docs-category\/servers\/"},{"term_name":"VPS-Servers","term_url":"https:\/\/www.truehost.com\/support\/docs-category\/vps-servers\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Compress and Decompress Files Using tar and gzip -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/\" \/>\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 tar and gzip -\" \/>\n<meta property=\"og:description\" content=\"Compressing and decompressing files is essential for saving disk space and transferring files efficiently. In Linux, the tar and gzip commands are commonly used for these purposes. Below is a guide on how to use these tools for compressing and decompressing files. What are tar and gzip? Installing tar and gzip Most Linux distributions come [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-02T09:57:50+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-compress-and-decompress-files-using-tar-and-gzip\\\/\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-compress-and-decompress-files-using-tar-and-gzip\\\/\",\"name\":\"How to Compress and Decompress Files Using tar and gzip -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#website\"},\"datePublished\":\"2024-11-02T09:57:19+00:00\",\"dateModified\":\"2024-11-02T09:57:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-compress-and-decompress-files-using-tar-and-gzip\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-compress-and-decompress-files-using-tar-and-gzip\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-compress-and-decompress-files-using-tar-and-gzip\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Compress and Decompress Files Using tar and gzip\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#website\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\",\"name\":\"\",\"description\":\"Help In a Click\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#organization\",\"name\":\"Truehost Kenya\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"contentUrl\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"width\":240,\"height\":48,\"caption\":\"Truehost Kenya\"},\"image\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Compress and Decompress Files Using tar and gzip -","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:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/","og_locale":"en_US","og_type":"article","og_title":"How to Compress and Decompress Files Using tar and gzip -","og_description":"Compressing and decompressing files is essential for saving disk space and transferring files efficiently. In Linux, the tar and gzip commands are commonly used for these purposes. Below is a guide on how to use these tools for compressing and decompressing files. What are tar and gzip? Installing tar and gzip Most Linux distributions come [&hellip;]","og_url":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/","article_modified_time":"2024-11-02T09:57:50+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/","url":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/","name":"How to Compress and Decompress Files Using tar and gzip -","isPartOf":{"@id":"https:\/\/www.truehost.com\/support\/#website"},"datePublished":"2024-11-02T09:57:19+00:00","dateModified":"2024-11-02T09:57:50+00:00","breadcrumb":{"@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-compress-and-decompress-files-using-tar-and-gzip\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.truehost.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to Compress and Decompress Files Using tar and gzip"}]},{"@type":"WebSite","@id":"https:\/\/www.truehost.com\/support\/#website","url":"https:\/\/www.truehost.com\/support\/","name":"","description":"Help In a Click","publisher":{"@id":"https:\/\/www.truehost.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.truehost.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.truehost.com\/support\/#organization","name":"Truehost Kenya","url":"https:\/\/www.truehost.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.truehost.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","contentUrl":"https:\/\/www.truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","width":240,"height":48,"caption":"Truehost Kenya"},"image":{"@id":"https:\/\/www.truehost.com\/support\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/docs\/16583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/comments?post=16583"}],"version-history":[{"count":1,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/docs\/16583\/revisions"}],"predecessor-version":[{"id":16584,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/docs\/16583\/revisions\/16584"}],"wp:attachment":[{"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/media?parent=16583"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/doc_category?post=16583"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/doc_tag?post=16583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}