{"id":4668,"date":"2023-07-22T10:02:41","date_gmt":"2023-07-22T10:02:41","guid":{"rendered":"https:\/\/arzhost.com\/blogs\/?p=4668"},"modified":"2024-12-03T20:55:51","modified_gmt":"2024-12-03T15:55:51","slug":"tar-command-in-linux","status":"publish","type":"post","link":"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/","title":{"rendered":"Tar Command in Linux: A Complete Guide with Examples"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Importance_in_File_Archiving_and_Compression\" >Importance in File Archiving and Compression<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Tar_Command_Syntax_How_to_Structure_Tar_Command_Lines\" >Tar Command Syntax: How to Structure Tar Command Lines<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#High-Performance_VPS_Hosting_Instant_Activation_Join_Now\" >High-Performance VPS Hosting: Instant Activation. Join Now!<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#List_of_Frequently_Used_Tar_Options_Common_Tar_Command_Options\" >List of Frequently Used Tar Options: Common Tar Command Options<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Practical_Examples_of_Tar_Commands_Detailed_Instructions\" >Practical Examples of Tar Commands: Detailed Instructions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#1_Creating_an_Archive_with_Tar\" >1: Creating an Archive with Tar<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Create_a_Basic_Tar_Archive_Step-by-Step_Guide\" >Create a Basic Tar Archive: Step-by-Step Guide<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Creating_a_targz_Compressed_Archive\" >Creating a tar.gz Compressed Archive<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Creating_a_tarbz2_Compressed_Archive\" >Creating a tar.bz2 Compressed Archive<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Creating_a_tarxz_Compressed_Archive\" >Creating a tar.xz Compressed Archive<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#2_Eliminating_Files_Following_Archive_Creation\" >2: Eliminating Files Following Archive Creation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#3_Extracting_Files_from_an_Archive\" >3: Extracting Files from an Archive<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Extracting_from_the_tar_archive_Basic_Extraction_Commands\" >Extracting from the tar archive: Basic Extraction Commands<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Extracting_from_a_targz_Archive\" >Extracting from a tar.gz Archive<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Extracting_from_a_tarbz2_Archive\" >Extracting from a tar.bz2 Archive<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Extracting_from_a_tarxz_Archive\" >Extracting from a tar.xz Archive<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#4_Commands_for_Rewriting_File_Ownership_Adjusting_Permissions\" >4: Commands for Rewriting File Ownership: Adjusting Permissions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#5_Commands_for_Viewing_Archive_Contents_Listing_Archive_Contents\" >5: Commands for Viewing Archive Contents: Listing Archive Contents<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#6_Finding_Files_in_an_Archive_Steps_to_Search_for_Specific_Files\" >6:\u00a0Finding Files in an Archive: Steps to Search for Specific Files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#7_Find_Multiple_Files_in_an_Archive_How_to_Locate_Multiple_Files_Efficiently\" >7: Find Multiple Files in an Archive: How to Locate Multiple Files Efficiently<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#8_Exclude_Files_When_Creating_an_Archive_Best_Practices_for_File_Exclusion\" >8: Exclude Files When Creating an Archive: Best Practices for File Exclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#9_Extracting_a_Single_File_from_an_Archive_Commands_for_Single_File\" >9: Extracting a Single File from an Archive: Commands for Single File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Pay_Once_Host_for_Life_%E2%80%93_Lifetime_Hosting_at_Unbeatable_Price\" >Pay Once, Host for Life &#8211; Lifetime Hosting at Unbeatable Price!<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#10_Using_the_Verbose_Option_Benefits_of_Using_Verbose_Output\" >10: Using the Verbose Option: Benefits of Using Verbose Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#11_Deleting_Files_from_an_Archive_Commands_for_File_Deletion\" >11: Deleting Files from an Archive: Commands for File Deletion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#12_Appending_Files_to_an_Existing_Archive_Steps_to_Add_Files\" >12: Appending Files to an Existing Archive: Steps to Add Files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#13_Combining_Multiple_Archives_Merge_Tar_Archives\" >13: Combining Multiple Archives: Merge Tar Archives<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#14_Difference_Between_Archive_and_Individual_Files\" >14: Difference Between Archive and Individual Files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#15_Updating_Files_within_an_Archive_Best_Practices_for_File_Updates\" >15: Updating Files within an Archive: Best Practices for File Updates<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#16_Modifying_File_Timestamps_Commands_for_Timestamp_Adjustment\" >16: Modifying File Timestamps: Commands for Timestamp Adjustment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#17_Managing_File_Permissions_in_an_Archive_Adjusting_Permissions\" >17: Managing File Permissions in an Archive: Adjusting Permissions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#The_Clocks_Ticking_24_Hours_Left_to_Claim_up_to_90_Off\" >The Clock&#8217;s Ticking! 24 Hours Left to Claim up to 90% Off<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#18_Changing_File_Ownership_in_Archives_Modify_File_Ownership\" >18: Changing File Ownership in Archives: Modify File Ownership<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#19_Writing_Archive_Data_to_External_Programs\" >19: Writing Archive Data to External Programs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#20_Creating_Daily_Backups_with_Tar_Setting_Up_Automated_Backups\" >20: Creating Daily Backups with Tar: Setting Up Automated Backups<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/arzhost.com\/blogs\/tar-command-in-linux\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Importance_in_File_Archiving_and_Compression\"><\/span>Importance in File Archiving and Compression<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In Linux systems, the most popular archiving tool is the GNU tar programmer (short for Tape Archiver). The Tar Command in Linux aids in creating, extracting, and listing archive contents and is directly accessible in the terminal.<\/p>\n\n\n\n<p>The tool is straightforward and offers a wide range of advantageous choices for managing backups, compressing data, and extracting a raw installation.<\/p>\n\n\n\n<p>This guide from our <a href=\"https:\/\/arzhost.com\/blogs\/\"><strong>Blog<\/strong><\/a> demonstrates the use of the <span style=\"color: #000000;\"><strong>Tar Command in Linux<\/strong> <\/span>using examples and all of the available options.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A system running Linux.<\/li>\n\n\n\n<li>Access to the command line\/terminal.<\/li>\n\n\n\n<li>A file or files for testing the command.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Tar_Command_Syntax_How_to_Structure_Tar_Command_Lines\"><\/span><strong>Tar Command Syntax<\/strong>: How to Structure Tar Command Lines<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>The general syntax for the tar command is:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar 'operation mode' 'options' 'archive' 'file' or 'location'<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>1: Which operation is performed on the files is indicated by the operation mode.<\/u><\/p>\n\n\n\n<p><u>2: (Conception, exploitation, etc.) The command only permits and necessitates one activity.<\/u><\/p>\n\n\n\n<p><u>3: Options are optional and change the operation mode. There is no restriction on the variety of choices.<\/u><\/p>\n\n\n\n<p><u>4: The file name and extension are the archives.<\/u><\/p>\n\n\n\n<p><u>5: A list of file names separated by spaces is used for extraction, compression, or wildcard matching.<\/u><\/p>\n\n\n\n<p><strong><u>The operations and options can be used in one of three syntax types:<\/u><\/strong><\/p>\n\n\n\n<p><u>1: Traditional style, clustered together without any dashes.<\/u><\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cfv &lt;archive> &lt;file(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>2: UNIX short option style, using a single dash and clustered options:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar -cfv &lt;archive> &lt;file(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Alternatively, a dash before each option:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar -c -f -v &lt;archive> &lt;file(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>3: GNU long-option style with a double-dash and a descriptive option name:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar --create --file &lt;archive> --verbose &lt;file(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p>All three styles can be used in a single Tar Command in <a href=\"https:\/\/en.wikipedia.org\/wiki\/Linux\" target=\"_blank\" rel=\"noopener\"><strong>Linux<\/strong><\/a>.<\/p>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-ea34b2e4 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><span class=\"ez-toc-section\" id=\"High-Performance_VPS_Hosting_Instant_Activation_Join_Now\"><\/span><a href=\"https:\/\/arzhost.com\/vps\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/vps\/\">High-Performance VPS Hosting: Instant Activation. Join Now!<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"uagb-cta__desc\">Dedicated Resources, Affordable Price: Sign Up for VPS Hosting at <strong>$12.50\/month<\/strong> with <a href=\"https:\/\/arzhost.com\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/\">ARZ Host<\/a>!<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/vps\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"List_of_Frequently_Used_Tar_Options_Common_Tar_Command_Options\"><\/span><strong>List of Frequently Used Tar Options: Common Tar Command Options<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The following table outlines the commonly used tar operations and options.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Command<\/strong><\/td><td><strong>Role<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>&#8211;create<br>\n-c<\/td><td>Operation<\/td><td>Creates a new archive.<\/td><\/tr><tr><td>&#8211;list<br>\n-t<\/td><td>Operation<\/td><td>Lists an archive&#8217;s contents.<\/td><\/tr><tr><td>&#8211;extract<br>\n-x<\/td><td>Operation<\/td><td>Extract one or more items from an archive.<\/td><\/tr><tr><td>&#8211;append<br>\n-r<\/td><td>Operation<\/td><td>Appends files to an existing archive.<\/td><\/tr><tr><td>&#8211;concatenate<br>\n-A<\/td><td>Operation<\/td><td>Appends archives to an existing archive.<\/td><\/tr><tr><td>&#8211;compare<br>\n&#8211;diff<br>\n-d<\/td><td>Operation<\/td><td>Compares archive members with files on the system.<\/td><\/tr><tr><td>&#8211;delete<\/td><td>Operation<\/td><td>Deletes a member from the archive.<\/td><\/tr><tr><td>&#8211;update<br>\n-u<\/td><td>Operation<\/td><td>Updates archive with new files only if they are not in the archive and are newer than existing files.<\/td><\/tr><tr><td>&#8211;file=&lt;archive&gt;<br>\n-f &lt;archive&gt;<\/td><td>Option<\/td><td>Specifies the file.<\/td><\/tr><tr><td>-C<\/td><td>Option<\/td><td>Changes the directory.<\/td><\/tr><tr><td>&#8211;verbose<br>\n-v<\/td><td>Option<\/td><td>Shows the file&nbsp;<strong>tar<\/strong>&nbsp;works on while running.<\/td><\/tr><tr><td>&#8211;wildcard<\/td><td>Option<\/td><td>Renders wildcard search options.<\/td><\/tr><tr><td>&#8211;bzip2<br>\n-j<\/td><td>Option<\/td><td>Read or write compressed archives through bzip2 format.<\/td><\/tr><tr><td>&#8211;gzip<br>\n-z<\/td><td>Option<\/td><td>Read or write compressed archives through gzip format.<\/td><\/tr><tr><td>&#8211;xz<br>\n-J<\/td><td>Option<\/td><td>Read or write compressed archives through xz format.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Follow the examples in the next section to learn how to work with tar.<\/p>\n\n\n\n<p><strong>Related Article: <a href=\"https:\/\/arzhost.com\/blogs\/different-between-linux-server-vs-windows-server\/\">Difference between Linux Server and Windows Server<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Practical_Examples_of_Tar_Commands_Detailed_Instructions\"><\/span><strong>Practical Examples of Tar Commands: Detailed Instructions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The criteria for the examples below are as follows:<\/p>\n\n\n\n<p><u>1: make a directory called &#8220;tar examples&#8221; and go there:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cd tar examples and then run \"mkdir tar examples\"<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>2: Create the following directory, files in tar examples, and enter it:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cd files and mkdir files<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>3: Produce documents to fill the files directory:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>open the file \"0.100.txt\"<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Use: to get back to the parent directory.<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cd.<\/code><\/li>\n<\/ul>\n\n\n\n<p>All the examples below work from the tar examples directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Creating_an_Archive_with_Tar\"><\/span><strong>1: Creating an Archive with Tar<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Depending on the type of archive, a certain syntax must be used. Use tar with the -c or \u2014create command to generate an archive.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_a_Basic_Tar_Archive_Step-by-Step_Guide\"><\/span><strong><u>Create a Basic Tar Archive<\/u><\/strong>: Step-by-Step Guide<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><u>Create a tar archive, often known as a tarball, by using:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf \"archive name\"<\/code><\/li>\n\n\n\n<li><code>tar files or directories<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>As an illustration, backup the files directory:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><u><code>files in tar cf format<\/code><\/u><\/li>\n<\/ul>\n\n\n\n<p><u>Each file added to the archive is listed in the output. To see the newly created file, show<\/u> <u>the directory contents. the tar archive<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>files in tar cf format<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Each file added to the archive is listed in the output. To see the newly created file, show the directory contents. the tar archive<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ls \u2013l<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_a_targz_Compressed_Archive\"><\/span><strong><u>Creating a tar.gz Compressed Archive<\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><u>Add the -z option to create a compressed GNU zip (gzip) file:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar czf &lt;archive name>. tar.gz &lt;file(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar czf files.tar.gz files<\/code><\/li>\n<\/ul>\n\n\n\n<p>The file size is smaller than a regular tarball file and the original directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_a_tarbz2_Compressed_Archive\"><\/span><strong><u>Creating a tar.bz2 Compressed Archive<\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The bzip2 is a file compression program and an alternative to gzip.<\/p>\n\n\n\n<p><u>To create a tar.bz2 file, add the -j tag:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cjf &lt;archive name>. tar.bz2 &lt;file(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cjf files.tar.bz2 files<\/code><\/li>\n<\/ul>\n\n\n\n<p>The bzip2 has a greater compression rate and takes longer than gzip.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_a_tarxz_Compressed_Archive\"><\/span><strong><u>Creating a tar.xz Compressed Archive<\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><u>Use the -J tag to compress archives in the tar.xz format:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cJf &lt;archive name>.tar. xz &lt;file(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cJf files.tar. xz files<\/code><\/li>\n<\/ul>\n\n\n\n<p>Wish to Use mkdir Command? Read our Detailed Guide on <a href=\"https:\/\/arzhost.com\/blogs\/use-mkdir-command-to-make\/\"><strong>How to Use the mkdir Command in Linux<\/strong><\/a> to Make or Create a Linux Directory<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Eliminating_Files_Following_Archive_Creation\"><\/span><strong>2: Eliminating Files Following Archive Creation<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>Use the \u2014remove-files option at the end to delete the files from disc after archiving:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf \"archive\" \"file\" \"location\" \u2014remove-files<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>As an illustration, execute the following Tar Command in Linux to build a tar archive of the files directory and delete it from the disc:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>files in tar cf format \u2014remove-files<\/code><\/li>\n<\/ul>\n\n\n\n<p>To ensure the procedure is successful, check the directory&#8217;s contents.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Extracting_Files_from_an_Archive\"><\/span><strong>3: Extracting Files from an Archive<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The -x or \u2014 extract operation with tar is used to extract from an archive or compressed archive. The extra choices are based on the file type and the location where tar should extract the parts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extracting_from_the_tar_archive_Basic_Extraction_Commands\"><\/span><strong><u>Extracting from the tar archive<\/u><\/strong>: Basic Extraction Commands<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><u>When extracting from a tar archive, the general syntax is:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Tar XF. Tar<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>The components are all extracted to the current directory by default when using tar. Add the -C option and the path to the command to specify where to extract the components:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>xfC tar xfC.tar<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Run the following command, for instance, to create the directory extracted tar and extract the files from files.tar.<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xfC files.tar extracted tar and mkdir extracted tar<\/code><\/li>\n<\/ul>\n\n\n\n<p>There is no confirmation message output by the command. Verify the directory&#8217;s contents to ensure that the components were correctly extracted.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extracting_from_a_targz_Archive\"><\/span><strong><u>Extracting from a tar.gz Archive<\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><u>Use the -z option to extract a tar.gz file:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xzf .tar.gz<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>The command extracts the contents in the current directory. Add the -C option to specify the location:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xzfC .tar.gz<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, create a new directory named extracted_gz and extract the files.tar.gz contents:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>mkdir extracted_gz &amp;&amp; tar xzfC files.tar.gz extracted_gz<\/code><\/li>\n<\/ul>\n\n\n\n<p>The tar.gz compressed archives take the least time to extract when compared to other compression formats.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extracting_from_a_tarbz2_Archive\"><\/span><strong><u>Extracting from a tar.bz2 Archive<\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><u>To extract files from a tar.bz2 compressed archive into the current directory, use:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xjf .tar.bz2<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Extract tar.bz2 archives into a specific directory with:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xjfC tar.bz2<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, create a directory and extract the contents from files.tar.bz2:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>mkdir extracted_bz2 &amp;&amp; tar xjfC files.tar.bz2 extracted_bz2<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extracting_from_a_tarxz_Archive\"><\/span><strong><u>Extracting from a tar.xz Archive<\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><u>Add the -J option to extract from tar. xz compressed archives. The syntax to extract in the current directory is:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xJf .tar.xz<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>To extract the contents to a specific directory, use the -C option and add the path:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xJfC .tar. xz<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>As an example, create a directory and extract the files.tar. xz contents:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>mkdir extracted_gz &amp;&amp; tar xJfC files.tar. xz extracted_gz<\/code><\/li>\n<\/ul>\n\n\n\n<p>The xz compression format is the middle ground between gz and bz2 when it comes to extraction time.<\/p>\n\n\n\n<p><iframe title=\"YouTube video player\" src=\"https:\/\/www.youtube.com\/embed\/s7HQjNhzNxI\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Commands_for_Rewriting_File_Ownership_Adjusting_Permissions\"><\/span><strong>4: Commands for Rewriting File Ownership: Adjusting Permissions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When the names of files in the working directory and the archive have the same names, tar overwrite controls handle the situation.<\/p>\n\n\n\n<p><u>1: These are the three potential overwrite actions:<\/u><\/p>\n\n\n\n<p><u>Files in the working directory should be overwritten:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf \"archive\", \"optional file(s), or (locations)\" \u2014overwrite<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>2: Refrain from replacing files in the working directory:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf \"archive\", \"optional file(s), or (locations)\" \u2014keep-old-files<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Tar does not extract the files if they already exist.<\/u><\/p>\n\n\n\n<p><u>3: Only extract files if they are more recent than the ones already present.<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf \"archive\", \"optional file(s), or (locations)\" \u2014keep-newer-files<\/code><\/li>\n<\/ul>\n\n\n\n<p>Tar does not extract files if the working directory&#8217;s files are more recent or the same age.<\/p>\n\n\n\n<p>Learn to <a href=\"https:\/\/arzhost.com\/blogs\/create-symbolic-links-in-linux\/\"><strong>Create Symbolic Links in Linux with this Easy to Follow Guide<\/strong><\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Commands_for_Viewing_Archive_Contents_Listing_Archive_Contents\"><\/span><strong>5: Commands for Viewing Archive Contents: Listing Archive Contents<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>Use the following command to list an archive&#8217;s contents:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf &lt;archive><\/code><\/li>\n<\/ul>\n\n\n\n<p>The option works for any file extension containing tar.<\/p>\n\n\n\n<p><u>For example, list the files and directories in the files.tar archive:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf files.tar.gz<\/code><\/li>\n<\/ul>\n\n\n\n<p>The output lists all contents stored in the archive.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Finding_Files_in_an_Archive_Steps_to_Search_for_Specific_Files\"><\/span><strong>6:\u00a0Finding Files in an Archive<\/strong>: Steps to Search for Specific Files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are two ways to locate specific content using tar:<\/p>\n\n\n\n<p><u>1: The -t option to list files in an archive is handy for locating specific files. Add the file name (or names) after the command:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf &lt;archive> &lt;file(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, to locate file50.txt in the files.tar.gz archive, run:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf files.tar.gz file\/file50.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p>The option requires knowing the possible path to the file.<\/p>\n\n\n\n<p><u>2: Use the tar together with the grep command to filter the output:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf &lt;archive> | grep &lt;file(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf files.tar.gz | grep file50.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p>The option doesn&#8217;t require knowing the possible path to the file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_Find_Multiple_Files_in_an_Archive_How_to_Locate_Multiple_Files_Efficiently\"><\/span><strong>7: Find Multiple Files in an Archive<\/strong>: How to Locate Multiple Files Efficiently<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>Use the &#8211;wildcards option to match multiple file instances. For example:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf files.tar.gz --wildcards file\/files5*.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p>Apply wildcard matching when files have a similar name, or for filtering a certain file type.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Exclude_Files_When_Creating_an_Archive_Best_Practices_for_File_Exclusion\"><\/span><strong>8: Exclude Files When Creating an Archive<\/strong>: Best Practices for File Exclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>To exclude certain files from the archive during creation, add the following option:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf &lt;archive> --exclude='&lt;pattern>' &lt;files(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, create an archive from the files directory and exclude all .txt files:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf files.tar --exclude='*.txt' files<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>List the archive contents:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf files.tar<\/code><\/li>\n<\/ul>\n\n\n\n<p>The output shows no .txt files, only the files directory in the archive.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"9_Extracting_a_Single_File_from_an_Archive_Commands_for_Single_File\"><\/span><strong>9: Extracting a Single File from an Archive: Commands for Single File<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Avoid extracting the whole archive if you need one or several files.<\/p>\n\n\n\n<p><u>To get a single file from an archive:<\/u><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2022\/12\/Extract-a-Single-File-from-the-Archive.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"364\" height=\"243\" title=\"Extract a Single File from the Archive\" src=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2022\/12\/Extract-a-Single-File-from-the-Archive.png\" alt=\"Extract a Single File from the Archive\" class=\"wp-image-4671\" srcset=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2022\/12\/Extract-a-Single-File-from-the-Archive.png 364w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2022\/12\/Extract-a-Single-File-from-the-Archive-300x200.png 300w\" sizes=\"(max-width: 364px) 100vw, 364px\" \/><\/a><\/figure><\/div>\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-ea34b2e4 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><span class=\"ez-toc-section\" id=\"Pay_Once_Host_for_Life_%E2%80%93_Lifetime_Hosting_at_Unbeatable_Price\"><\/span><a href=\"https:\/\/arzhost.com\/lifetime-web-hosting\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/lifetime-web-hosting\/\">Pay Once, Host for Life &#8211; Lifetime Hosting at Unbeatable Price!<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"uagb-cta__desc\">Host for Life, Pay Just Once &#8211; Grab Lifetime Web Hosting with a Bonus Domain!<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/lifetime-web-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<p><u>1: List the contents and check if the file exists:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf files.tar | grep file100.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p>The output prints the path to the file needed for the next step.<\/p>\n\n\n\n<p><u>2: Extract the specific file with:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf files.tar files\/file100.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p>The Tar Command in Linux only includes the specified file when creating the directory files. By adding the proper tag, repeat these procedures to extract a single file from compressed archives. For instance, to pull from a tar.gz file, use the -z option.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"10_Using_the_Verbose_Option_Benefits_of_Using_Verbose_Output\"><\/span><strong>10: Using the Verbose Option: Benefits of Using Verbose Output<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The verbose option displays additional information after running a tar command. Add -v or &#8211;verbose to any operation to see the result.<\/p>\n\n\n\n<p><u>For example, create a tar.gz file and add -v:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar czfv files.tar.gz files<\/code><\/li>\n<\/ul>\n\n\n\n<p>The output shows each file as it is added to the archive.<\/p>\n\n\n\n<p><u>Some tar commands show additional information when you add the -v tag twice. For example, try to add files to an archive with -vv:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar czfvv files.tar.gz files<\/code><\/li>\n<\/ul>\n\n\n\n<p>The output prints a long listing format and looks similar to running the ls -l command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"11_Deleting_Files_from_an_Archive_Commands_for_File_Deletion\"><\/span><strong>11: Deleting Files from an Archive<\/strong>: Commands for File Deletion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>To delete from the archive, locate the file you want to remove, for example:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tf files.tar | grep file100.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Then, remove the file using the &#8211;delete tag:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar --delete -f files.tar files\/file100.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p>The delete option does not work on compressed file formats.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"12_Appending_Files_to_an_Existing_Archive_Steps_to_Add_Files\"><\/span><strong>12: Appending Files to an Existing Archive: Steps to Add Files<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>Append files to an existing archive using the -r tag. The syntax is:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar rf &lt;archive name>.tar &lt;file(s) or location(s)><\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, append the compressed files.tar.gz file to the files.tar archive:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar rf files.tar files.tar.gz<\/code><\/li>\n<\/ul>\n\n\n\n<p>Already compressed archives cannot be updated. So the syntax only works for tarball files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"13_Combining_Multiple_Archives_Merge_Tar_Archives\"><\/span><strong>13: Combining Multiple Archives<\/strong>: Merge Tar Archives<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>Use the &#8211;concatenate or -A option to combine multiple archives. The basic syntax is:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar Af<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>As an example, copy the existing files.tar file using the cp command:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cp files.tar files_copy.tar<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Next, concatenate the two archives:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar Af files.tar files_copy.tar<\/code><\/li>\n<\/ul>\n\n\n\n<p>To confirm the concatenation worked, check the file size. Have file Permission problems? check out How to <a href=\"https:\/\/arzhost.com\/blogs\/change-file-permissions-recursively-chmod-linux\/\"><strong>Change File Permissions with chmod in Linux<\/strong><\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"14_Difference_Between_Archive_and_Individual_Files\"><\/span><strong>14: Difference Between Archive and Individual Files<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>To check the difference between an archive and files on disk, use the -d tag:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar df<\/code><\/li>\n<\/ul>\n\n\n\n<p>The command looks for identical items and contrasts them with the contents of the archive. The option ignores newly inserted files and only looks for existing files.<\/p>\n\n\n\n<p><strong><u>The steps below show how to use the -d, &#8211;diff, or &#8211;compare tag with tar:<\/u><\/strong><\/p>\n\n\n\n<p><u>1: Create a tar archive:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf files.tar files<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>2: Compare the archive with the existing directory:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar df files.tar<\/code><\/li>\n<\/ul>\n\n\n\n<p>The output does not display anything, meaning there is no difference between the existing files.<\/p>\n\n\n\n<p><u>3: Add text to an existing file in the files directory:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>echo 'Hello' >> files\/file0.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>4: Compare the archive to the existing directory again:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar df files.tar<\/code><\/li>\n<\/ul>\n\n\n\n<p>This time, the report reveals variations in the size and modification time for a particular file. Comparing sheds light on any system modifications performed after the archive was created.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"15_Updating_Files_within_an_Archive_Best_Practices_for_File_Updates\"><\/span><strong>15: Updating Files within an Archive: Best Practices for File Updates<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>Update the existing files in the archive with a newer version from disk with the -u option:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar uf<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, update the files.tar archive with a changed text file:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar uf files.tar files<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Check the tar contents for the changed file:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar tfv files.tar | grep files0.txt<\/code><\/li>\n<\/ul>\n\n\n\n<p>The command updates the archive with changed files without any overwrites.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"16_Modifying_File_Timestamps_Commands_for_Timestamp_Adjustment\"><\/span><strong>16: Modifying File Timestamps<\/strong>: Commands for Timestamp Adjustment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>Tar offers various options to modify the file&#8217;s timestamp. Set a custom date when creating an archive by adding the &#8211;mtime option and providing a date:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf --mtime=YYYY-MM-DD<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, create an archive and set the date to January 1st, 1999:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf files.tar files --mtime=1999-01-01<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Alternatively, extract the files with the current date and time:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf files.tar -m<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>A useful feature when working with time is filtering files modified after a specific date. For example, to extract files created after a date, use the &#8211;newer-mtime option and add the date:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf --newer-mtime=YYYY-MM-DD<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"17_Managing_File_Permissions_in_an_Archive_Adjusting_Permissions\"><\/span><strong>17: Managing File Permissions in an Archive: Adjusting Permissions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are two possible ways to control file permissions with tar when extracting an archive:<\/p>\n\n\n\n<p><u>1: Preserve original permissions:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf --preserve-permissions<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>The permissions are as stated in the file before archive creation.<\/u><\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p><u>2: Modify the permissions to the default umask value:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf --no-same-permissions<\/code><\/li>\n<\/ul>\n\n\n\n<p>The files take on the default Linux permissions.<\/p>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-f75fffa7 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><span class=\"ez-toc-section\" id=\"The_Clocks_Ticking_24_Hours_Left_to_Claim_up_to_90_Off\"><\/span><a href=\"https:\/\/arzhost.com\/web-hosting\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/web-hosting\/\">The Clock&#8217;s Ticking! 24 Hours Left to Claim up to 90% Off<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2><p class=\"uagb-cta__desc\">Seize the Savings Now\u2014Lock in Your Discount at <a href=\"https:\/\/arzhost.com\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\">ARZ Host<\/a> Before Time Runs Out!<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/web-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"18_Changing_File_Ownership_in_Archives_Modify_File_Ownership\"><\/span><strong>18: Changing File Ownership in Archives: Modify File Ownership<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>Tar allows file ownership configuration. For example, to set the file owner when creating an archive, add the &#8211;owner and &#8211;group options and provide values for each:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf --owner= --group=<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>The owner value represents the UID (User ID) while the group value is the GID (Group ID). To find these values for a user, run:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>id<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, create an archive and set the ownership to root:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar cf files.tar files --owner=0 --group=0<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Tar allows preserving the ownership when extracting from an archive. To do so, add the &#8211;same-owner option at the end:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf --same-owner<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"19_Writing_Archive_Data_to_External_Programs\"><\/span><strong>19: Writing Archive Data to External Programs<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>The &#8211;to-command option instructs tar to send each extracted file to the standard output for an external program. The basic syntax is:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf --to-command=''<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, extract the files.tar contents and pipe the file names as directories:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar xf files.tar --to-command='mkdir $TAR_FILENAME'<\/code><\/li>\n<\/ul>\n\n\n\n<p>Each extracted file is given its own directory, which the command creates. Visit the manual page for more details and a list of the available Linux environment variables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"20_Creating_Daily_Backups_with_Tar_Setting_Up_Automated_Backups\"><\/span><strong>20: Creating Daily Backups with Tar: Setting Up Automated Backups<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><u>To automate daily backups, create a bash script and add the following lines:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>tar czf backup-$(date +%Y%m%d). tar.gz files<\/code><\/li>\n\n\n\n<li><code>find backup* -mtime +1 -delete<\/code><\/li>\n<\/ul>\n\n\n\n<p>The find command looks for backup files older than one day, whereas the tar tool builds a compressed archive. For weekly or monthly backups, change the +1 parameter to +7 or +31, respectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You are familiar with how to use the Tar Command in Linux after reading this tutorial. There are, however, several additional options that are not covered in this guide. To learn everything there is to know about tar options, use the man command.<\/p>\n\n\n\n<p><strong>Read More:<\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/how-to-fix-403-forbidden-error-wordpress\/\">How To Fix 403 Forbidden Error WordPress<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/how-to-get-the-most-out-of-claude-ai\/\">How To Get The Most Out Of Claude Ai<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/bad-gateway-error-502-the-ultimate-guide-to-quick-fixes\/\">Bad Gateway Error (502): The Ultimate Guide to Quick Fixes<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/a-deep-dive-into-todays-best-linux-distros\/\">A Deep Dive Into Today\u2019s Best Linux Distros<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/domain-investor-terms-powerful-strategy\/\">Domain Investor Terms: Expert Insight on Powerful Strategy<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Importance in File Archiving and Compression In Linux systems, the most popular archiving tool is the GNU tar programmer (short for Tape Archiver). The Tar Command in Linux aids in creating, extracting, and listing archive contents and is directly accessible in the terminal. The tool is straightforward and offers a wide range of advantageous choices [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6119,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"table_tags":[],"class_list":["post-4668","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/4668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/comments?post=4668"}],"version-history":[{"count":6,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/4668\/revisions"}],"predecessor-version":[{"id":11047,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/4668\/revisions\/11047"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media\/6119"}],"wp:attachment":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media?parent=4668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/categories?post=4668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/tags?post=4668"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/table_tags?post=4668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}