{"id":80,"date":"2018-04-24T05:42:38","date_gmt":"2018-04-24T05:42:38","guid":{"rendered":"http:\/\/td_uid_31_5adec3ced9450"},"modified":"2018-05-25T10:09:32","modified_gmt":"2018-05-25T10:09:32","slug":"how-to-compress-and-extract-files-using-the-tar-command-on-linux","status":"publish","type":"post","link":"https:\/\/forumweb.hosting\/blog\/how-to-compress-and-extract-files-using-the-tar-command-on-linux\/","title":{"rendered":"How to Compress and Extract Files Using the tar Command on Linux"},"content":{"rendered":"<p><a href=\"https:\/\/forumweb.hosting\/blog\/wp-content\/uploads\/2018\/04\/tar-command-in-Linux.jpg\"><img loading=\"lazy\" class=\"wp-image-434 alignleft\" src=\"https:\/\/forumweb.hosting\/blog\/wp-content\/uploads\/2018\/04\/tar-command-in-Linux.jpg\" alt=\"\" width=\"310\" height=\"172\" srcset=\"https:\/\/forumweb.hosting\/blog\/wp-content\/uploads\/2018\/04\/tar-command-in-Linux.jpg 547w, https:\/\/forumweb.hosting\/blog\/wp-content\/uploads\/2018\/04\/tar-command-in-Linux-300x166.jpg 300w\" sizes=\"(max-width: 310px) 100vw, 310px\" \/><\/a>Tar command which is brief word of &#8220;tape archive&#8221;, is used by Linux\/Unix system administrators. The purpose of the tar command is to create, compress, decompress and view the contents of compressed files. This makes it easier to save and move files from one computer to another. Let&#8217;s learn how to use the tar command.<\/p>\n<p><strong>Compresses the directory using the tar command<\/strong><br \/>\nAssuming that the \/home\/filename directory exists, the tar command is used to compress this directory<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>#tar -cvf filename.tar\/home\/filename<\/p><\/blockquote>\n<p>In this case, the option has the following meaning:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>\u00a0-c: create tar file<br \/>\n-v: show process execution<br \/>\n-f: tar file name created<\/p><\/blockquote>\n<p>If you want to compress the file using gzip, we can use option z as follows:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>#tar -cvzf filename.tar\/home\/filename<\/p><\/blockquote>\n<p><strong>Decompression<\/strong><br \/>\nAssuming that the compressed file is filename.tar, to extract this file in the current directory we do as follows:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p># tar -xvf filename.tar<\/p><\/blockquote>\n<p>In the case of extracting the tar file to the specified directory:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p># tar -xvf filename.tar -C \/home\/username\/test\/<br \/>\nOr use &#8220;tar -zxvf&#8221; to extract the * .tar.gz file.<br \/>\nOr use &#8220;tar -jxvf&#8221; to extract the * .tar.bz2 file.<\/p><\/blockquote>\n<p><strong>Extract some files with wildcard<\/strong><br \/>\nAssuming that the compressed file is filename.tar, only extract the. C file in this file we do as follows:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p># tar -xvf filename.tar &#8211;wildcard &#8216;* .c&#8217;<br \/>\nSame with * .tar.gz and * .tar.bz2:<br \/>\n#tar -zxvf filename.tar.gz &#8211;wildcard &#8216;* .c&#8217;<br \/>\n#tar -jxvf filename.tar.b2z &#8211;wildcard &#8216;* .c&#8217;<\/p><\/blockquote>\n<p><strong>Extract the specified files<\/strong><br \/>\nAssuming that the compressed file is filename.tar, only extract file1 and file2 but in this file we do as follows:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p># tar -xvf filename.tar &#8220;file1&#8221; &#8220;file2&#8221;<\/p><\/blockquote>\n<p>Same with * .tar.gz and * .tar.bz2:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p># tar -zxvf filename.tar.gz &#8220;file1&#8221; &#8220;file2&#8221;<br \/>\n# tar -jxvf filename.tar.b2z &#8220;file1&#8221; &#8220;file2&#8221;<\/p><\/blockquote>\n<p><strong>Displays the contents of the tar file<\/strong><br \/>\nTo display the files, folders in file &#8220;filename.tar&#8221;, we execute the following command:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>#tar -tvf filename.tar<\/p><\/blockquote>\n<p>This command can also be used with * .tar.gz and * .tar.bz2:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>#tar -tvf filename.tar.gz<br \/>\n#tar -tvf filename.tar.b2z<\/p><\/blockquote>\n<p><strong>Add files or directories to existing tar files<\/strong><br \/>\nPlease remember that tar command does not have the option to do this task.<\/p>\n<p>Good luck!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tar command which is brief word of &#8220;tape archive&#8221;, is used by Linux\/Unix system administrators. The purpose of the tar command is to create, compress, decompress and view the contents of compressed files. This makes it easier to save and move files from one computer to another. Let&#8217;s learn how to use the tar command. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":434,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[59,58],"_links":{"self":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/80"}],"collection":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":10,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":439,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/80\/revisions\/439"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/media\/434"}],"wp:attachment":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}