{"id":18029,"date":"2022-08-03T18:51:37","date_gmt":"2022-08-03T18:51:37","guid":{"rendered":"https:\/\/linuxways.net\/?p=18029"},"modified":"2022-09-05T18:04:20","modified_gmt":"2022-09-05T18:04:20","slug":"tar-command-options-examples","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/tar-command-options-examples\/","title":{"rendered":"TAR Command Options and Examples"},"content":{"rendered":"<p>TAR is a very powerful Linux command that is generally used for compressing the multiple files into a single TAR file. However, apart from that, it can also be used for printing the contents of a TAR file, extracting the contents of a TAR file, etc. In this guide, we will discuss the options that can be used with this command as well as a few use-cases in which this command can prove to be extremely helpful.<\/p>\n<h2><strong>Options Used with the TAR Command<\/strong><\/h2>\n<p>To take a look at all the options that are available with the TAR command, you can run the following command:<\/p>\n<pre>\r\n$ tar --help\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"313\" height=\"25\" class=\"wp-image-18033\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-1.png 313w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-1-300x24.png 300w\" sizes=\"auto, (max-width: 313px) 100vw, 313px\" \/><\/strong><\/p>\n<p>The options available with the TAR command are shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"657\" height=\"409\" class=\"wp-image-18035\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-2.png 657w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-2-300x187.png 300w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/p>\n<h2><strong>Examples of Using the TAR Command<\/strong><\/h2>\n<p>Following are a few examples that will help you out in using the TAR command in an effective manner:<\/p>\n<h3><strong>Example 1: Compress Multiple Files into a TAR File<\/strong><\/h3>\n<p>In this example, we compress the multiple text files into a single TAR file. For that, we run the following command:<\/p>\n<pre>\r\n$ tar \u2013czvf files.tar.gz file1.txt file2.txt file3.txt\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"25\" class=\"wp-image-18036\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-3.png 647w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-3-300x12.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/strong><\/p>\n<p>This command creates a TAR file named \u201cfiles.tar.gz\u201d and adds the text files named \u201cfile1.txt\u201d, \u201cfile2.txt\u201d, and \u201cfile3.txt\u201d to this TAR file.<\/p>\n<p>The compression of these files produces the following output on the terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"646\" height=\"109\" class=\"wp-image-18038\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-4.png 646w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-4-300x51.png 300w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/p>\n<h2><strong>Example 2: View the Contents of a TAR File<\/strong><\/h2>\n<p>You can also display the contents of a TAR file by running the following command:<\/p>\n<pre>\r\n$ tar \u2013tf files.tar.gz\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"396\" height=\"23\" class=\"wp-image-18040\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-5.png 396w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-5-300x17.png 300w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/strong><\/p>\n<p>The contents of our TAR file are shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"415\" height=\"102\" class=\"wp-image-18044\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-6.png 415w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-6-300x74.png 300w\" sizes=\"auto, (max-width: 415px) 100vw, 415px\" \/><\/p>\n<h2><strong>Example 3: Add Another File to a TAR File<\/strong><\/h2>\n<p>In this example, we add a text file to an already existing TAR file. For that, we use the following command:<\/p>\n<pre>\r\n$ tar \u2013rvf files.tar file4.txt\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"459\" height=\"25\" class=\"wp-image-18048\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-7.png 459w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-7-300x16.png 300w\" sizes=\"auto, (max-width: 459px) 100vw, 459px\" \/><\/strong><\/p>\n<p>If the name of the file to be added appears in the output, it means that the specified file has been successfully added to the TAR file as shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"487\" height=\"59\" class=\"wp-image-18051\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-8.png 487w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-8-300x36.png 300w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/p>\n<h2><strong>Example 4: Remove a File from a TAR File<\/strong><\/h2>\n<p>In this example, we attempt to remove a file from a TAR file. For that, we use the following command:<\/p>\n<pre>\r\n$ tar --delete \u2013f files.tar file4.txt\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"514\" height=\"26\" class=\"wp-image-18053\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-9.png 514w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-9-300x15.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-9-501x26.png 501w\" sizes=\"auto, (max-width: 514px) 100vw, 514px\" \/><\/strong><\/p>\n<p>This command removes the file named \u201cfile4.txt\u201d from our TAR file as shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"517\" height=\"41\" class=\"wp-image-18055\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-10.png 517w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-10-300x24.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18029-10-501x41.png 501w\" sizes=\"auto, (max-width: 517px) 100vw, 517px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>This article explained the usage of the TAR command in Linux. After giving you an overview of this command, we shared the command with which you can view all the options available with this command. After that, we shared some examples with you that makes the usage of this command easier for you.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Article guide on the options that can be used with the TAR command in Linux as well as a few use-cases in which this command can prove to be extremely helpful.<\/p>","protected":false},"author":3,"featured_media":18097,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-18029","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=18029"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18029\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/18097"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=18029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=18029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=18029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}