{"id":2136,"date":"2013-06-27T12:04:23","date_gmt":"2013-06-27T04:04:23","guid":{"rendered":"http:\/\/rmohan.com\/?p=2136"},"modified":"2013-06-28T10:43:56","modified_gmt":"2013-06-28T02:43:56","slug":"gnu-tar-tape-archive","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2136","title":{"rendered":"GNU tar (Tape ARchive)"},"content":{"rendered":"<p>GNU tar (Tape ARchive) saves multiple files together into a single tape or disk archive, and can restore individual files from the archive. Here are some Linux tar Command with Useful Practical Examples<\/p>\n<p>Some useful command line switches are given below, which are used in this article.<\/p>\n<p>c =&gt; create an archive file.<br \/>\nv =&gt; show the detailed output ( or porgress ) of command.<br \/>\nx =&gt; extract an archive file.<br \/>\nf =&gt; filename of archive file.<br \/>\nz =&gt; Use archive through gzip.<br \/>\nt =&gt; viewing content of archive file.<br \/>\nj =&gt; Use archive through bzip2.<br \/>\nC =&gt; Use of define destination directory.<br \/>\nW =&gt; Verify a archive file.<br \/>\nExample 1: Create a .tar Archive File.<\/p>\n<p>Below command will create an compressed ( tar ) file using all files and directories ( with subdirectories ) of \/var\/log directory.<\/p>\n<p># tar cvf rmohan-16-apr-2013.tar \/var\/log<br \/>\nExample 2: Create a .tar.gz Archive File.<\/p>\n<p>Below command will create an gzip compressed ( tar.gz ) file using all files and directories ( with subdirectories ) of \/var\/log directory. I will create more compressed file than .tar file.<\/p>\n<p># tar czvf rmohan-16-apr-2013.tar.gz \/var\/log<br \/>\nExample 3: Create a .tar.bz2 Archive File.<\/p>\n<p>This example is used for creating bz2 files. bz2 files are higher compressed than .tar and .tar.gz files. Its also take more time to compress than others.<\/p>\n<p># tar cjvf rmohan-16-apr-2013.tar.bz2 \/var\/log<br \/>\nCheck difference between .tar , .tar.gz and .tar.bz2 file sizes.<\/p>\n<p># ls -l rmohan-16-apr-2013.tar*<br \/>\n-rw-r&#8211;r&#8211;. 1 root root 26818560 Apr 12 22:25 rmohan-16-apr-2013.tar<br \/>\n-rw-r&#8211;r&#8211;. 1 root root 697802 Apr 13 00:25 rmohan-16-apr-2013.tar.bz2<br \/>\n-rw-r&#8211;r&#8211;. 1 root root 1091399 Apr 13 00:26 rmohan-16-apr-2013.tar.gz<br \/>\nAs per above output .tar.bz2 is higher compressed and .tar is lower compressed file.<\/p>\n<p>Example 4: List content of .tar, .tar.gz, .tar.bz2 Archive File.<\/p>\n<p>Some times we requried to list content of archive file without extracting them. Below example will help you to do it.<\/p>\n<p># tar -tvf rmohan-16-apr-2013.tar<br \/>\n# tar -tvf rmohan-16-apr-2013.tar.gz<br \/>\n# tar -tvf rmohan-16-apr-2013.tar.bz2<br \/>\nExample 5: Uncompress .tar Archive File.<\/p>\n<p>To uncompress a .tar file use below command. It will extract all files and directories ( with subdirectories ) in current path. To uncompress in different location check Example 8.<\/p>\n<p># tar -xvf rmohan-16-apr-2013.tar<br \/>\nExample 6: Uncompress .tar.gz Archive File.<\/p>\n<p>To uncompress a .tar.gz ( tar + gzip ) file use below command. It will extract all files and directories in current path.<\/p>\n<p># tar -xvf rmohan-16-apr-2013.tar<br \/>\nExample 7: Uncompress .tar.bz2 Archive File.<\/p>\n<p>Use below example to uncompress a .tar.bz2 ( tar + bz2 ) file. It will extract all files and directories in current path.<\/p>\n<p># tar -xvf rmohan-16-apr-2013.tar<br \/>\nExample 8: Extract Archive in different location.<\/p>\n<p>Use C command line switch to specify a location for extracting an archive file.<\/p>\n<p># tar xf rmohan-16-apr-2013.tar -C \/Output\/Dir\/<br \/>\nExample 9: Verify .tar Archive Files.<\/p>\n<p>To verify .tar file use \u2018W\u2019 switch with \u2018t\u2019. For you information .tar.gz and .tar.bz2 can not be verified using this. Use below command to verify your tar file.<\/p>\n<p># tar tvWf \/root\/rmohan-16-apr-2013.tar<br \/>\nSample Output:<\/p>\n<p>tar: This does not look like a tar archive<br \/>\ntar: Skipping to next header<br \/>\ntar: VERIFY FAILURE: 13 invalid headers detected<br \/>\nVerify -rw&#8212;&#8212;- root\/root 0 2013-03-31 03:50 var\/log\/spooler-20130407<br \/>\nVerify -rw&#8212;&#8212;- root\/utmp 384 2013-04-12 21:31 var\/log\/btmp<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 211614 2013-03-18 19:20 var\/log\/dracut.log<br \/>\nVerify -rw&#8212;&#8212;- root\/root 5793 2013-04-12 22:20 var\/log\/secure<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 4952 2013-04-01 14:40 var\/log\/krb5kdc.log-20130401<br \/>\nVerify drwxr-xr-x root\/root 0 2011-12-08 06:00 var\/log\/spice-vdagentd\/<br \/>\nVerify drwx&#8212;&#8212; root\/root 0 2013-04-12 14:57 var\/log\/samba\/<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 0 2013-04-09 01:58 var\/log\/samba\/log.192.168.1.199<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 1972 2013-04-12 14:37 var\/log\/samba\/log.nmbd<br \/>\nvar\/log\/samba\/log.nmbd: Mod time differs<br \/>\nvar\/log\/samba\/log.nmbd: Size differs<br \/>\nVerify -rw&#8212;&#8212;- root\/utmp 384 2013-03-18 20:26 var\/log\/btmp-20130401<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 1382 2013-04-11 13:53 var\/log\/kadmind.log<br \/>\nVerify drwxrwx&#8211;T root\/gdm 0 2013-04-11 13:53 var\/log\/gdm\/<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 0 2013-04-11 13:53 var\/log\/gdm\/:0-slave.log<br \/>\nVerify -rw-r&#8211;r&#8211; gdm\/gdm 1387 2013-04-05 17:07 var\/log\/gdm\/:0-greeter.log.1<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 18983 2013-03-25 14:10 var\/log\/gdm\/:0.log.3<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 19028 2013-04-05 17:06 var\/log\/gdm\/:0.log.1<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 18983 2013-03-22 15:42 var\/log\/gdm\/:0.log.4<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 98 2013-04-05 17:07 var\/log\/gdm\/:0-slave.log.1<br \/>\nVerify -rw-r&#8211;r&#8211; root\/root 18983 2013-04-11 13:53 var\/log\/gdm\/:0.log<br \/>\ntar: Exiting with failure status due to previous errors<br \/>\nDue to long list of output, some of output has been hidden in above command output.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GNU tar (Tape ARchive) saves multiple files together into a single tape or disk archive, and can restore individual files from the archive. Here are some Linux tar Command with Useful Practical Examples<\/p>\n<p>Some useful command line switches are given below, which are used in this article.<\/p>\n<p>c =&gt; create an archive file. v =&gt; [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2136"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2136"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2136\/revisions"}],"predecessor-version":[{"id":2138,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2136\/revisions\/2138"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}