{"id":15712,"date":"2019-02-28T15:09:30","date_gmt":"2019-02-28T15:09:30","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15712"},"modified":"2025-12-02T15:37:29","modified_gmt":"2025-12-02T15:37:29","slug":"linux-tar-command-with-examples","status":"publish","type":"post","link":"\/ca\/tutorials\/linux-tar-command-with-examples\/","title":{"rendered":"How to use the tar command in Linux"},"content":{"rendered":"<p>The <strong>tar<\/strong> command in Linux <strong>simplifies file management by enabling efficient archiving and compression<\/strong>.<\/p><p>Originally designed for tape archives, it has become an essential tool for grouping multiple files and directories into a single <strong>.tar<\/strong> file, often called a tarball.<\/p><p>With this command, you can create, extract, update, delete, and compress files &ndash; all directly from the command line.<\/p><p>Scroll down to learn the <strong>tar <\/strong>command&rsquo;s syntax and the most common options. We&rsquo;ll cover everything from creating and extracting Linux archive files to advanced tasks like updating and deleting their contents.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-69262\"  sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure>\n<\/div><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-is-the-tar-command-in-linux\">What is the tar command in Linux?<\/h2><p>The <strong>tar<\/strong> (tape archive) command is a <strong>command-line utility to create and manage archive files<\/strong>. Its main function is to combine multiple files and directories into a single archive, making storage and transfer more efficient.<\/p><p>A tar archive is commonly used for:<\/p><ul class=\"wp-block-list\">\n<li><strong>Backup<\/strong>. Automate daily server or website backups.<\/li>\n\n\n\n<li><strong>Transfer<\/strong>. Bundle project files for easy sharing.<\/li>\n\n\n\n<li><strong>Storage<\/strong>. Compress large directories to save disk space.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-tar-command-syntax\">Tar command syntax<\/h2><p>The <strong>tar<\/strong> command follows simple syntax. Understanding each component is the first step to using it effectively.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar [options] [archive-file] [file\/directory...]<\/pre><ul class=\"wp-block-list\">\n<li><strong>[options]<\/strong>. Single-letter flags that define the action, such as create (<strong>-c<\/strong>), extract (<strong>-x<\/strong>), or list (<strong>-t<\/strong>).<\/li>\n\n\n\n<li><strong>[archive-file]<\/strong>. The name of the archive, for example <strong>backup.tar<\/strong> or <strong>project.tar.gz<\/strong>.<\/li>\n\n\n\n<li><strong>[file\/directory&hellip;]<\/strong>. The files or directories to include in the archive. You can list multiple items separated by spaces.<\/li>\n<\/ul><p>For example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -cvf backup.tar \/home\/user\/documents<\/pre><p>This command creates an archive named <strong>backup.tar<\/strong> in the <strong>\/home\/user\/documents<\/strong> directory.<\/p><h3 class=\"wp-block-heading\" id=\"h-most-common-tar-options\">Most common tar options<\/h3><p>The <strong>tar<\/strong> command&rsquo;s functionality is controlled by its options. While there are many options available, the most commonly used are listed below.<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>Option<\/strong><\/td><td><strong>Long option<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>-c<\/td><td>&ndash;create<\/td><td>Creates a new archive file.<\/td><\/tr><tr><td>-x<\/td><td>&ndash;extract<\/td><td>Extracts files from an existing archive.<\/td><\/tr><tr><td>-t<\/td><td>&ndash;list<\/td><td>Lists the contents of an archive without extracting them.<\/td><\/tr><tr><td>-f<\/td><td>&ndash;file<\/td><td>Specifies the name of the archive file. This is almost always required.<\/td><\/tr><tr><td>-v<\/td><td>&ndash;verbose<\/td><td>Displays a detailed list of the files being processed.<\/td><\/tr><tr><td>-z<\/td><td>&ndash;gzip<\/td><td>Compresses the archive using gzip, creating a <strong>.tar.gz<\/strong> file.<\/td><\/tr><tr><td>-j<\/td><td>&ndash;bzip<\/td><td>Compresses the archive using bzip2, creating a <strong>.tar.bz2<\/strong> file.<\/td><\/tr><tr><td>-J<\/td><td>&ndash;xz<\/td><td>Compresses the archive using xz, creating a <strong>.tar.xz<\/strong> file.<\/td><\/tr><tr><td>-r<\/td><td>&ndash;append<\/td><td>Adds new files to the end of an existing archive.<\/td><\/tr><tr><td>-u<\/td><td>&ndash;update<\/td><td>Adds files to an archive only if they are newer than the existing ones.<\/td><\/tr><tr><td><\/td><td>&ndash;delete<\/td><td>Deletes files from an archive. <strong>Note<\/strong>: This doesn&rsquo;t work on tape drives.<\/td><\/tr><\/tbody><\/table><\/figure><p>You can combine multiple options in one command like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -czvf project.tar.gz project\/<\/pre><p>This creates a gzip-compressed archive of the <strong>project\/<\/strong> directory and displays the files being added.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-create-archives-using-tar\">How to create archives using tar<\/h2><p>The <strong>tar<\/strong> command uses the <strong>-c<\/strong> option to create new archive files. This is particularly useful for creating a single backup file of your website&rsquo;s project directory before making any changes.<\/p><h3 class=\"wp-block-heading\" id=\"h-create-uncompressed-archives\">Create uncompressed archives<\/h3><p>To create a plain archive without compression (simply bundling files together):<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -cvf website-backup.tar file1.html file2.css images\/<\/pre><p><strong>Expected output<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file1.html\nfile2.css\nimages\/\nimages\/logo.png\nimages\/banner.jpg<\/pre><h3 class=\"wp-block-heading\" id=\"h-create-compressed-archives-gzip-bzip2-xz\">Create compressed archives (gzip, bzip2, xz)<\/h3><p>Compression reduces the archive size. <strong>tar<\/strong> supports multiple compression algorithms:<\/p><ul class=\"wp-block-list\">\n<li><strong>gzip (-z)<\/strong>. Fast and widely used.<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -czvf website-backup.tar.gz file1.html file2.css images\/<\/pre><ul class=\"wp-block-list\">\n<li><strong>bzip2 (-j)<\/strong>. Offers better compression than gzip but is slower.<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -cjvf website-backup.tar.bz2 file1.html file2.css images\/<\/pre><ul class=\"wp-block-list\">\n<li><strong>xz (-J)<\/strong>. Provides the highest compression ratio, but is also the slowest.<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -cJvf website-backup.tar.xz file1.html file2.css images\/<\/pre><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    &#128161; When to use gzip vs bzip2 vs xz                <\/p>\n            <\/div>\n            <p class=\"protip__content\">Use <strong>gzip<\/strong> for quick, everyday tasks, <strong>bzip2<\/strong> when you need a balance of speed and compression, and <strong>xz<\/strong> for long-term storage where maximum space savings are important.<\/p>\n                    <\/div>\n        \n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-extract-archives-with-tar\">How to extract archives with tar<\/h2><p>To extract a tar archive in Linux, use the <strong>-x<\/strong> option. This unpacks the contents, restoring the original files and directory structure &ndash; a crucial step when deploying a web application from a backup.<\/p><h3 class=\"wp-block-heading\" id=\"h-extract-to-current-directory\">Extract to current directory<\/h3><p>To unpack an archive into your current directory:<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -xvf website-backup.tar.gz<\/pre><p><strong>Expected output<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file1.html\nfile2.css\nimages\/\nimages\/logo.png\nimages\/banner.jpg<\/pre><h3 class=\"wp-block-heading\" id=\"h-extract-to-a-custom-directory\">Extract to a custom directory<\/h3><p>To extract the archive&rsquo;s contents into a specific directory, use the <strong>-C<\/strong> option.<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -xzvf website-backup.tar.gz -C \/var\/www\/html<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-add-files-to-existing-tar-archives\">How to add files to existing tar archives<\/h2><p>You can add files to an existing archive using the <strong>-r<\/strong> option. This is useful for adding new log files to a backup without recreating the entire archive. Note that you cannot add files to compressed archives, such as <strong>.tar.gz<\/strong>.<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -rvf website-backup.tar file3.js fonts\/<\/pre><p><strong>Expected output<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file3.js\nfonts\/\nfonts\/roboto.woff<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-list-tar-archive-contents\">How to list tar archive contents<\/h2><p>Use the <strong>-t<\/strong> option to view files inside an archive without extracting them. This is perfect for verifying what&rsquo;s inside a backup before you restore it.<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -tvf website-backup.tar.gz<\/pre><p><strong>Expected output<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-rw-r--r-- user\/group      1234 2025-08-21 10:30 file1.html\n-rw-r--r-- user\/group      5678 2025-08-21 10:30 file2.css\ndrwxr-xr-x user\/group         0 2025-08-21 10:30 images\/\n-rw-r--r-- user\/group     15200 2025-08-21 10:30 images\/logo.png\n-rw-r--r-- user\/group     45800 2025-08-21 10:30 images\/banner.jpg<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-extract-specific-files-using-tar\">How to extract specific files using tar<\/h2><p>You don&rsquo;t have to extract everything. <strong>tar<\/strong> can restore selected files, saving time and disk space if you only need one or two files from a large backup.<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -xzvf website-backup.tar.gz file1.html images\/logo.png<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-update-existing-tar-archives\">How to update existing tar archives<\/h2><p>Use the <strong>-u<\/strong> option to replace files inside an archive with newer versions. <strong>tar<\/strong> checks the file&rsquo;s modification timestamp and updates it only if the local version is newer than the one in the archive.<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -uvf archive.tar updatedfile.txt<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-concatenate-multiple-tar-archives\">How to concatenate multiple tar archives<\/h2><p>Concatenating lets you merge several tar files into one using the <strong>-A<\/strong> (<strong>&ndash;catenate<\/strong>) option. This is helpful for merging weekly backups into a single monthly archive.<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -Af main-archive.tar week2.tar week3.tar<\/pre><p>This appends the contents of <strong>week2.tar<\/strong> and <strong>week3.tar<\/strong> into <strong>main-archive.tar<\/strong>.<\/p><p><div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> You cannot directly merge compressed formats like <strong>.tar.gz<\/strong> or <strong>.tar.xz<\/strong> with <strong>.tar<\/strong>.\n            <\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-delete-files-from-tar-archives\">How to delete files from tar archives<\/h2><p>The <strong>tar<\/strong> command can also remove files or entire directories from an uncompressed archive with the <strong>&ndash;delete<\/strong> option.<\/p><p><strong>Command<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar --delete -f website-backup.tar images\/banner.jpg\ntar --delete -f website-backup.tar unused-directory\/<\/pre><p>Note that the <strong>&ndash;delete<\/strong> option may not be available in older versions of tar. In that instance, you&rsquo;ll have to extract the archive, remove the unwanted files manually, and then recreate it.<\/p><p>Check our guide on <a href=\"\/ca\/tutorials\/how-to-remove-directory-in-linux\/\">how to remove a directory in Linux<\/a>, which provides alternative methods for deleting both empty and non-empty directories.<\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/ca\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-key-takeaways-about-the-tar-command\">Key takeaways about the tar command<\/h2><p>Mastering the <strong>tar<\/strong> command is a valuable skill for anyone working in a Linux environment. It provides a powerful and flexible way to manage files efficiently.<\/p><ul class=\"wp-block-list\">\n<li><strong>Flexible archiving<\/strong>. The primary strength of <strong>tar<\/strong> is its ability to bundle countless files and directories into a single, portable archive file.<\/li>\n\n\n\n<li><strong>Built-in compression<\/strong>. With support for gzip, bzip2, and xz, <strong>tar<\/strong> lets you significantly reduce archive size, saving valuable disk space.<\/li>\n\n\n\n<li><strong>Efficient file management<\/strong>. From creating backups to packaging project files for sharing, <strong>tar<\/strong> streamlines system administration tasks and keeps your workflow organized.<\/li>\n<\/ul><p>As a next step, practice these command examples in a safe directory. Try creating different types of compressed archives and inspect their contents.<\/p><p>For more advanced options and edge cases, consult the official manual page by running <strong>man tar<\/strong> in your terminal.<\/p><p>We also suggest exploring other <a href=\"\/ca\/tutorials\/linux-commands\/\">Linux commands<\/a> like <strong>cp<\/strong> (for copying files) and <strong>rsync<\/strong> (for synchronizing backups) to enhance your system administration skills.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tar command in Linux simplifies file management by enabling efficient archiving and compression. Originally designed for tape archives, it has become an essential tool for grouping multiple files and directories into a single .tar file, often called a tarball. With this command, you can create, extract, update, delete, and compress files &ndash; all directly [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ca\/tutorials\/linux-tar-command-with-examples\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":411,"featured_media":139856,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to use the tar command in Linux (With examples)","rank_math_description":"Learn how to use the Linux tar command to create, extract, compress, and manage archive files with practical examples.","rank_math_focus_keyword":"tar command","footnotes":""},"categories":[22703,22699],"tags":[],"class_list":["post-15712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/linux-tar-command-with-examples\/","default":1},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/comando-tar-linux\/","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/commande-tar-sur-linux\/","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-usar-comando-tar-linux\/","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/tar-linux\/","default":0},{"locale":"nl-NL","link":"https:\/\/www.hostinger.com\/nl\/tutorials\/tar-command\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-use-the-tar-command-in-linux\/","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-use-the-tar-command-in-linux\/","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/linux-tar-command-with-examples\/","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/linux-tar-command-with-examples\/","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/linux-tar-command-with-examples\/","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/linux-tar-command-with-examples\/","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/linux-tar-command-with-examples\/","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-usar-comando-tar-linux\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/como-usar-comando-tar-linux\/","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-usar-comando-tar-linux\/","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/comando-tar-linux\/","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/15712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/users\/411"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/comments?post=15712"}],"version-history":[{"count":34,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/15712\/revisions"}],"predecessor-version":[{"id":139855,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/15712\/revisions\/139855"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media\/139856"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media?parent=15712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/categories?post=15712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/tags?post=15712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}