{"id":14503,"date":"2025-09-10T07:05:09","date_gmt":"2025-09-10T07:05:09","guid":{"rendered":"https:\/\/www.bodhost.com\/kb\/?p=14503"},"modified":"2026-02-26T14:02:06","modified_gmt":"2026-02-26T14:02:06","slug":"how-to-use-the-tar-command-in-linux","status":"publish","type":"post","link":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/","title":{"rendered":"How to use the tar command in Linux"},"content":{"rendered":"<p>The tar command is one of the most useful tools in Linux systems. It helps you archive, compress, and extract files and directories. Whether you&#8217;re backing up data or transferring files, tar makes the process simple and efficient.<\/p>\n<p>In this tutorial, we\u2019ll look at how to use the tar command in Linux. Follow the steps below to archive, compress, extract, and manage files efficiently using the tar command.<\/p>\n<h2><strong>What is the tar command?<\/strong><\/h2>\n<p>We use the tar command to compress and extract files from the command line. The basic syntax is shown below:<\/p>\n<pre><span style=\"color: #3366ff;\">tar [flags] destinationFileName sourceFileName<\/span><\/pre>\n<p>The tar command uses the following options to customize how it works:<\/p>\n<table>\n<thead>\n<tr>\n<th><span style=\"color: #333333;\">Option<\/span><\/th>\n<th><span style=\"color: #333333;\">Description<\/span><\/th>\n<th><span style=\"color: #333333;\">When to Use<\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>-c<\/td>\n<td>Create a new archive.<\/td>\n<td>Use this when you want to make a new archive file.<\/td>\n<\/tr>\n<tr>\n<td>-z<\/td>\n<td>Use gzip compression.<\/td>\n<td>Use this when you want the archive compressed with gzip.<\/td>\n<\/tr>\n<tr>\n<td>-v<\/td>\n<td>Provide verbose output.<\/td>\n<td>The -v option shows details of the files being compressed or extracted.<\/td>\n<\/tr>\n<tr>\n<td>-f<\/td>\n<td>Archive file name.<\/td>\n<td>Use this to specify the name of the archive file (e.g., -f backup.tar).<\/td>\n<\/tr>\n<tr>\n<td>-x<\/td>\n<td>Extract from an archive.<\/td>\n<td>Use this when you need to extract files from an archive.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>1. Create a Tar Archive<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar -cvf backup.tar \/home\/user\/files\/<\/span><\/pre>\n<p>Explanation:<\/p>\n<ul>\n<li>-c: Creates a new archive<\/li>\n<li>-v: Shows the progress in the terminal<\/li>\n<li>-f: Specifies the name of the archive file<\/li>\n<\/ul>\n<p>This command creates an archive named backup.tar containing the contents of \/home\/user\/files\/.<\/p>\n<h4><strong>2. Compress an Archive Using Gzip<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar -czvf backup.tar.gz \/home\/user\/files\/<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>-z: Compresses the archive using gzip<\/p>\n<p>Other options are the same as above<\/p>\n<p>This creates a compressed archive named backup.tar.gz.<\/p>\n<h4><strong>3. Compress an Archive Using Bzip2<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar -cjvf backup.tar.bz2 \/home\/user\/files\/<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>-j: Compresses the archive using bzip2<\/p>\n<p>This creates a smaller archive using bzip2 compression.<\/p>\n<h4><strong>4. Extract a Tar Archive<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar -xvf backup.tar<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>-x: Extracts files from the archive<\/p>\n<p>This command extracts all files from backup.tar into the current directory.<\/p>\n<h4><strong>5. Extract a Gzip Compressed Archive<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar -xzvf backup.tar.gz<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>-z: Tells tar to use gzip to decompress<\/p>\n<p>This extracts files from a .tar.gz archive.<\/p>\n<h4><strong>6. Extract a Bzip2 Compressed Archive<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar -xjvf backup.tar.bz2<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>-j: Tells tar to use bzip2 to decompress<\/p>\n<p>This extracts files from a .tar.bz2 archive.<\/p>\n<h4><strong>7. View Contents of an Archive Without Extracting<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar -tvf backup.tar<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>-t: Lists the contents of the archive<\/p>\n<p>This shows you what\u2019s inside the archive without extracting it.<\/p>\n<p><strong>8. Add a File to an Existing Archive<\/strong><\/p>\n<pre><span style=\"color: #3366ff;\">tar -rvf backup.tar newfile.txt<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>-r: Appends files to an existing archive<\/p>\n<p>This adds newfile.txt to backup.tar. Note: This only works with uncompressed .tar files.<\/p>\n<h4><strong>9. Delete a File from an Archive<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar --delete -f backup.tar unwanted.txt<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>&#8211;delete: Removes a file from the archive<\/p>\n<p>This deletes unwanted.txt from backup.tar. This option may not work with compressed archives.<\/p>\n<h4><strong>10. Estimate Archive Size Before Creating<\/strong><\/h4>\n<pre><span style=\"color: #3366ff;\">tar -cf - \/home\/user\/files\/ | wc -c<\/span><\/pre>\n<p>Explanation:<\/p>\n<p>-cf -: Creates an archive and sends it to standard output<br \/>\nwc -c: Counts the number of bytes<\/p>\n<p>This helps you estimate how large the archive will be.<\/p>\n<p>The tar command is a powerful and flexible tool for managing files in Linux. Whether you&#8217;re backing up data, compressing files, or extracting archives, these commands will help you handle your tasks efficiently. If you need help using the tar command or face any issues, feel free to contact our 24\/7 support team.<\/p>\n<p>Learn more tutorials on <a href=\"https:\/\/www.bodhost.com\/kb\/how-to-extract-or-unzip-tar-gz-files-in-linux\/\" target=\"_blank\" rel=\"noopener\"><em>How to Extract or Unzip .tar.gz Files in Linux<\/em><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tar command is one of the most useful tools in Linux systems. It helps you archive, compress, and extract files and directories. Whether you&#8217;re backing up data or transferring&hellip;<\/p>\n<p><a href=\"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/\" class=\"more-link\">Read More<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[837],"tags":[1643],"class_list":["post-14503","post","type-post","status-publish","format-standard","hentry","category-tutorial","tag-tar-command-in-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to use the tar command in Linux<\/title>\n<meta name=\"description\" content=\"Learn how to use the tar command in Linux servers to archive, compress, extract, &amp; manage files efficiently with simple steps &amp; examples.\" \/>\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.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use the tar command in Linux\" \/>\n<meta property=\"og:description\" content=\"Learn how to use the tar command in Linux servers to archive, compress, extract, &amp; manage files efficiently with simple steps &amp; examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - bodHOST\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-10T07:05:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T14:02:06+00:00\" \/>\n<meta name=\"author\" content=\"Paul Lopez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Lopez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-use-the-tar-command-in-linux\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-use-the-tar-command-in-linux\\\/\"},\"author\":{\"name\":\"Paul Lopez\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/566ccff9a2fae4af852be8097b179813\"},\"headline\":\"How to use the tar command in Linux\",\"datePublished\":\"2025-09-10T07:05:09+00:00\",\"dateModified\":\"2026-02-26T14:02:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-use-the-tar-command-in-linux\\\/\"},\"wordCount\":542,\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"keywords\":[\"Tar Command in Linux\"],\"articleSection\":[\"Tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-use-the-tar-command-in-linux\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-use-the-tar-command-in-linux\\\/\",\"name\":\"How to use the tar command in Linux\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\"},\"datePublished\":\"2025-09-10T07:05:09+00:00\",\"dateModified\":\"2026-02-26T14:02:06+00:00\",\"description\":\"Learn how to use the tar command in Linux servers to archive, compress, extract, & manage files efficiently with simple steps & examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-use-the-tar-command-in-linux\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-use-the-tar-command-in-linux\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-use-the-tar-command-in-linux\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tutorial\",\"item\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/category\\\/tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use the tar command in Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"alternateName\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"contentUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"width\":240,\"height\":240,\"caption\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/566ccff9a2fae4af852be8097b179813\",\"name\":\"Paul Lopez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"caption\":\"Paul Lopez\"},\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/author\\\/paullopez\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use the tar command in Linux","description":"Learn how to use the tar command in Linux servers to archive, compress, extract, & manage files efficiently with simple steps & examples.","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.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"How to use the tar command in Linux","og_description":"Learn how to use the tar command in Linux servers to archive, compress, extract, & manage files efficiently with simple steps & examples.","og_url":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/","og_site_name":"Knowledge Base - bodHOST","article_published_time":"2025-09-10T07:05:09+00:00","article_modified_time":"2026-02-26T14:02:06+00:00","author":"Paul Lopez","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Paul Lopez","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/#article","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/"},"author":{"name":"Paul Lopez","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/566ccff9a2fae4af852be8097b179813"},"headline":"How to use the tar command in Linux","datePublished":"2025-09-10T07:05:09+00:00","dateModified":"2026-02-26T14:02:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/"},"wordCount":542,"publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"keywords":["Tar Command in Linux"],"articleSection":["Tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/","url":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/","name":"How to use the tar command in Linux","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/#website"},"datePublished":"2025-09-10T07:05:09+00:00","dateModified":"2026-02-26T14:02:06+00:00","description":"Learn how to use the tar command in Linux servers to archive, compress, extract, & manage files efficiently with simple steps & examples.","breadcrumb":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.bodhost.com\/kb\/how-to-use-the-tar-command-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Tutorial","item":"https:\/\/www.bodhost.com\/kb\/category\/tutorial\/"},{"@type":"ListItem","position":2,"name":"How to use the tar command in Linux"}]},{"@type":"WebSite","@id":"https:\/\/www.bodhost.com\/kb\/#website","url":"https:\/\/www.bodhost.com\/kb\/","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","description":"","publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"alternateName":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bodhost.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.bodhost.com\/kb\/#organization","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","url":"https:\/\/www.bodhost.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","contentUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","width":240,"height":240,"caption":"Web Hosting Knowledge Base | bodHOST Hosting FAQ"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/566ccff9a2fae4af852be8097b179813","name":"Paul Lopez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","caption":"Paul Lopez"},"url":"https:\/\/www.bodhost.com\/kb\/author\/paullopez\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/14503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/comments?post=14503"}],"version-history":[{"count":11,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/14503\/revisions"}],"predecessor-version":[{"id":14651,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/14503\/revisions\/14651"}],"wp:attachment":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/media?parent=14503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/categories?post=14503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/tags?post=14503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}