{"id":21735,"date":"2023-09-30T17:33:05","date_gmt":"2023-09-30T17:33:05","guid":{"rendered":"https:\/\/linuxways.net\/?p=21735"},"modified":"2023-09-30T17:33:05","modified_gmt":"2023-09-30T17:33:05","slug":"how-to-create-a-tar-file-in-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-create-a-tar-file-in-linux-ubuntu\/","title":{"rendered":"How to Create a tar File in Linux\/Ubuntu?"},"content":{"rendered":"<p><strong>Data compression<\/strong> is done to optimize data storage on storage mediums like SSD, Cloud, etc. Data compression results in larger storage availability, cost savings due to larger space availability, and faster data transfer rates.<\/p>\n<p><strong>Tar <\/strong>is a command line tool that handles a variety of compression formats like \u201c.<strong>gz<\/strong>\u201d, \u201c.<strong>xz<\/strong>\u201d, \u201c.<strong>tbz<\/strong>\u201d, \u201c<strong>.bz2<\/strong>\u201d etc. This article will demonstrate the creation of three tar compression formats on Linux\/Ubuntu 22.04. LTS systems.<\/p>\n<h2><a id=\"post-21735-_tdaaiahbt8gi\"><\/a>How to Create a tar.gz File in Linux\/Ubuntu?<\/h2>\n<p>The \u201c<strong>tar.gz<\/strong>\u201d is a compressed archive file format for Linux systems that uses the \u201cgzip\u201d compression algorithm.<\/p>\n<p>Consider that we have a set of five text files: \u201cFile1.txt, File2.txt, File3.txt, File4.txt, and File5.txt\u201d in a directory that needs to be compressed as shown below:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<h2><a id=\"post-21735-_uurkuikbh5k6\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"1654\" height=\"362\" class=\"wp-image-21736\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-1.png 1654w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-1-300x66.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-1-1024x224.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-1-768x168.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-1-1536x336.png 1536w\" sizes=\"auto, (max-width: 1654px) 100vw, 1654px\" \/><\/h2>\n<p>We will run the following command to compress these five files to create a tar.gz compressed archive:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">tar<\/span> czf archive.tar.gz <span class=\"sy0\">*<\/span>.txt<\/div><\/div>\n<p>The above command comprises of:<\/p>\n<ul>\n<li>tar: tar command line tool<\/li>\n<li>c: Creates a new archive.<\/li>\n<li>z: Constructs the compressed archive using \u201cgzip\u201d.<\/li>\n<li>f: file<\/li>\n<li>archive.tar.gz: Name of the archive file.<\/li>\n<li>*.txt: Select all the .txt files in the present working directory.<\/li>\n<\/ul>\n<h2><\/h2>\n<h2><a id=\"post-21735-_en0cxjibugls\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"1806\" height=\"104\" class=\"wp-image-21737\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-2.png 1806w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-2-300x17.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-2-1024x59.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-2-768x44.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-2-1536x88.png 1536w\" sizes=\"auto, (max-width: 1806px) 100vw, 1806px\" \/><\/h2>\n<p>We can verify the created archive.tar.gz archive by using the following ls command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<p>From the below image, we can see that a .tar.gz compressed archive \u201carchieve.tar.gz\u201d is created.<\/p>\n<h2><a id=\"post-21735-_5tqqunmqbptl\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"1730\" height=\"422\" class=\"wp-image-21738\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-3.png 1730w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-3-300x73.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-3-1024x250.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-3-768x187.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-3-1536x375.png 1536w\" sizes=\"auto, (max-width: 1730px) 100vw, 1730px\" \/><\/h2>\n<h2><a id=\"post-21735-_htmwupdlkg1g\"><\/a>How to Create a tar.xz File in Linux\/Ubuntu?<\/h2>\n<p>The \u201c<strong>tar.xz<\/strong>\u201d is a compressed archive file format for Linux systems that uses LZMA\/LZMA2 compression algorithms.<\/p>\n<p>Consider that we have a set of five text files: \u201cFile1.txt, File2.txt, File3.txt, File4.txt, and File5.txt\u201d in a directory that needs to be compressed as shown below:<\/p>\n<h2><a id=\"post-21735-_7yy4sid24hh0\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"1654\" height=\"362\" class=\"wp-image-21739\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-4.png 1654w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-4-300x66.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-4-1024x224.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-4-768x168.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-4-1536x336.png 1536w\" sizes=\"auto, (max-width: 1654px) 100vw, 1654px\" \/><\/h2>\n<p>We will run the following command to compress these five files into a tar.xz compressed archive:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">tar<\/span> cfJ archive2.tar.xz <span class=\"sy0\">*<\/span>.txt<\/div><\/div>\n<p>The above command comprises of:<\/p>\n<ul>\n<li>tar: tar command line tool.<\/li>\n<li>c: Create a new archive.<\/li>\n<li>f: file<\/li>\n<li>J: Create the compressed files using \u201c.xz\u201d.<\/li>\n<li>archive2.tar.xz: Name of the archive file.<\/li>\n<li>*.txt: Select all the .txt files in the present working directory.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1656\" height=\"98\" class=\"wp-image-21740\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-5.png 1656w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-5-300x18.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-5-1024x61.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-5-768x45.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-5-1536x91.png 1536w\" sizes=\"auto, (max-width: 1656px) 100vw, 1656px\" \/><\/p>\n<p>We will verify the created \u201carchive2.tar.xz\u201d archive via the \u201cls -l\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<p>From the below image, it can be verified that a .tar.xz compressed archive \u201carchieve2.tar.gz\u201d is created.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1740\" height=\"512\" class=\"wp-image-21741\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-6.png 1740w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-6-300x88.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-6-1024x301.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-6-768x226.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-6-1536x452.png 1536w\" sizes=\"auto, (max-width: 1740px) 100vw, 1740px\" \/><\/p>\n<h2><a id=\"post-21735-_etnmgbdzqu5v\"><\/a>How to Create a tar.bz2 File in Linux\/Ubuntu?<\/h2>\n<p>The \u201c<strong>.tar.bz2<\/strong>\u201d is a compressed archive file format for Linux systems that is highly optimized for compression with the BZ2 compression algorithm.<\/p>\n<p>Consider that we have a set of five text files: \u201cFile1.txt, File2.txt, File3.txt, File4.txt, and File5.txt\u201d in a directory that needs to be compressed as shown below:<\/p>\n<h2><a id=\"post-21735-_r9sse69yhnq7\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"1654\" height=\"362\" class=\"wp-image-21742\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-7.png 1654w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-7-300x66.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-7-1024x224.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-7-768x168.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-7-1536x336.png 1536w\" sizes=\"auto, (max-width: 1654px) 100vw, 1654px\" \/><\/h2>\n<p>We will run the following command to compress these five files into a tar.bz2 compressed archive:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">tar<\/span> <span class=\"re5\">-cvjf<\/span> archive1.tar.bz2 <span class=\"sy0\">*<\/span>.txt<\/div><\/div>\n<p>The above command comprises of:<\/p>\n<ul>\n<li>tar: tar command line tool.<\/li>\n<li>c: Create\/Make a new archive.<\/li>\n<li>v: verbose<\/li>\n<li>j: Creates the compressed files using \u201cbz2\u201d.<\/li>\n<li>f: File<\/li>\n<li>archive1.tar.gz: Name of the archive file.<\/li>\n<li>*.txt: Select all the .txt files in the present working directory.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1708\" height=\"330\" class=\"wp-image-21743\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-8.png 1708w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-8-300x58.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-8-1024x198.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-8-768x148.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-8-1536x297.png 1536w\" sizes=\"auto, (max-width: 1708px) 100vw, 1708px\" \/><\/p>\n<p>We can verify the created archive1.tar.bz2 archive by using the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<p>From the below image, it can be verified that a .tar.bz2 compressed archive named \u201carchieve1.tar.gz\u201d is created:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1800\" height=\"476\" class=\"wp-image-21744\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-9.png 1800w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-9-300x79.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-9-1024x271.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-9-768x203.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21735-9-1536x406.png 1536w\" sizes=\"auto, (max-width: 1800px) 100vw, 1800px\" \/><\/p>\n<h2><a id=\"post-21735-_x2d18vwtpzgj\"><\/a>Conclusion<\/h2>\n<p>Various compressed archives are created by using the Tar command line tool, such as tar.gz, tar.xz, and tar.bz2. Compressed archives are created using \u201ctar czf &lt;archive_name.tar.gz&gt; &lt;file.txt&gt;\u201d, \u201ctar cfJ &lt;archive_name.tar.xz&gt; &lt;file.txt&gt;\u201d, and \u201ctar -cvjf &lt;archive_name.tar.bz2&gt; &lt;file.txt&gt;\u201d commands respectively. This article has demonstrated the creation of three tar compression formats on Linux\/Ubuntu 22.04. LTS systems.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>To create a tar file in Linux\/Ubuntu, various compressed archives are created by using the Tar command line tool, such as tar.gz, tar.xz, and tar.bz2, etc.<\/p>","protected":false},"author":110,"featured_media":21745,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049,2],"tags":[],"class_list":["post-21735","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21735","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\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=21735"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21735\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/21745"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=21735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=21735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=21735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}