{"id":614,"date":"2012-02-27T06:51:27","date_gmt":"2012-02-27T11:51:27","guid":{"rendered":"https:\/\/www.bodhost.com\/blog\/?p=614"},"modified":"2026-02-26T13:59:06","modified_gmt":"2026-02-26T13:59:06","slug":"uses-of-tar-command-in-unix-and-linux-server","status":"publish","type":"post","link":"https:\/\/www.bodhost.com\/blog\/uses-of-tar-command-in-unix-and-linux-server\/","title":{"rendered":"Uses of Tar Command in Unix and Linux Server"},"content":{"rendered":"\r\n<h3><strong>Uses of Tar Command in Unix and Linux Server :<\/strong><\/h3>\r\n\r\n\r\n\r\n<p>For archiving purposes on the Unix platform, <strong>tar command<\/strong> is the command to be used. Knowing the various tar command options will help you to be a master of archive file manipulation.<\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span style=\"font-size: large;\">A. Create an archive with the tar command<\/span><\/h4>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* Create an uncompressed tar archive with option cvf<\/span><\/p>\r\n\r\n\r\n\r\n<p>It is the most basic command to create a tar archive.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar cvf archive_name.tar dirname\/\r\nNote :\r\nc \u2013 create a new archive\r\nv \u2013 verbosely list files which are processed.\r\nf \u2013 following is the archive file name<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* Create a tar gzipped archive with option cvzf<\/span><\/p>\r\n\r\n\r\n\r\n<p>The above used tar cvf, can&#8217;t offer any compression. So, if you want to utilize a gzip compression on the tar archive then you can utilize the z option as follows.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar cvzf archive_name.tar.gz dirname\/\r\nNote :\r\nz \u2013 filter the archive through gzip<\/pre>\r\n\r\n\r\n\r\n<p>Note:<\/p>\r\n\r\n\r\n\r\n<p>.tgz is similar as .tar.gz<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* Create a bzipped tar archive with option cvjf<\/span><\/p>\r\n\r\n\r\n\r\n<p>Create a bzip2 tar archive as shown below:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar cvfj archive_name.tar.bz2 dirname\/\r\nNote :\r\nj \u2013 filter the archive through bzip2<\/pre>\r\n\r\n\r\n\r\n<p><strong>Note:<\/strong><\/p>\r\n\r\n\r\n\r\n<p>.tbz and .tb2 is similar as .tar.bz2<\/p>\r\n\r\n\r\n\r\n\r\n\r\n<h4><span style=\"font-size: large;\"><strong>B. Extracting (untar) an archive with the tar command<\/strong><\/span><\/h4>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* Extract a *.tar file with option xvf<\/span><\/p>\r\n\r\n\r\n\r\n<p>Extract a tar file with options x as shown below:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar xvf archive_name.tar\r\nNote :\r\nx \u2013 extract files from archive<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* Extract a gzipped tar archive ( *.tar.gz ) with option xvzf<\/span><\/p>\r\n\r\n\r\n\r\n<p>Use the option z for uncompressing a gzip tar archive.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar xvfz archive_name.tar.gz<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* Extract a bzipped tar archive ( *.tar.bz2 ) with option xvjf<\/span><\/p>\r\n\r\n\r\n\r\n<p>Use the option j for uncompressing a bzip2 tar archive.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar xvfj archive_name.tar.bz2<\/pre>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><strong><span style=\"font-size: large;\">C. Listing an archive with tar command<\/span><\/strong><\/h4>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* View the tar archive file content without extracting with option tvf<\/span><\/p>\r\n\r\n\r\n\r\n<p>You can find out the *.tar file content before extracting as shown below.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar tvf archive_name.tar<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* View the *.tar.gz file content without extracting with option tvzf<\/span><\/p>\r\n\r\n\r\n\r\n<p>You can find out the *.tar.gz file content before extracting as shown below.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar tvfz archive_name.tar.gz<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-heading\"><span style=\"font-size: medium;\">* View the *.tar.bz2 file content without extracting using option tvjf<\/span><\/p>\r\n\r\n\r\n\r\n<p>You can find out the *.tar.bz2 file content before extracting as shown below.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar tvfj archive_name.tar.bz2<\/pre>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><strong><span style=\"font-size: large;\">D. Process To Add a file or directory to an existing archive With option -r<\/span><\/strong><\/h4>\r\n\r\n\r\n\r\n<p>You can add additional files to an existing tar archive as shown below. Like, to append a file to *.tar file do the following:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar rvf archive_name.tar updatedfile<\/pre>\r\n\r\n\r\n\r\n<p>This updated file will be added to the existing archive_name.tar. Adding a directory to the tar is also similar,<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar rvf archive_name.tar newdir\/<\/pre>\r\n\r\n\r\n\r\n<p>Note:<\/p>\r\n\r\n\r\n\r\n<p>You can&#8217;t add a file or directory to a compressed archive. In that case, you will get the following error<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar rvfz archive_name.tgz newfile\r\ntar: Cannot update compressed archives\r\nTry `tar --help' or `tar --usage' for more information.<\/pre>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><strong><span style=\"font-size: large;\">E. Way To Estimate The tar Archive Size<\/span><\/strong><\/h4>\r\n\r\n\r\n\r\n<p>Before creating the tar file you can estimate the tar file size ( in KB ) with the command below:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ tar -cf - \/directory\/to\/archive\/ | wc -c\r\n20480<\/pre>\r\n\r\n\r\n\r\n<p>Before creating the tar.gz, tar.bz2 files, you can estimates the compressed tar file size ( in KB ) with the commands below:<\/p>\r\n\r\n\r\n\r\n<p>$ tar -czf &#8211; \/directory\/to\/archive\/ | wc -c 508 $ tar -cjf &#8211; \/directory\/to\/archive\/ | wc -c 428<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Uses of Tar Command in Unix and Linux Server : For archiving purposes on the Unix platform, tar command is the command to be used. Knowing the various tar command options will help you to be a master of archive file manipulation. A. Create an archive with the tar command * Create an uncompressed tar [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[149],"tags":[77,151],"class_list":["post-614","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux-server","tag-tar-command"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/posts\/614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/comments?post=614"}],"version-history":[{"count":10,"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/posts\/614\/revisions"}],"predecessor-version":[{"id":5631,"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/posts\/614\/revisions\/5631"}],"wp:attachment":[{"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/media?parent=614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/categories?post=614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bodhost.com\/blog\/wp-json\/wp\/v2\/tags?post=614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}