{"id":1107,"date":"2010-08-28T12:35:29","date_gmt":"2010-08-28T05:35:29","guid":{"rendered":"http:\/\/www.jfdesignnet.com\/?p=1107"},"modified":"2010-08-28T12:35:29","modified_gmt":"2010-08-28T05:35:29","slug":"some-tar-tricks","status":"publish","type":"post","link":"https:\/\/www.jfdesignnet.com\/?p=1107","title":{"rendered":"Some tar tricks"},"content":{"rendered":"<p><a href=\"http:\/\/www.jfdesignnet.com\/wp-content\/uploads\/2010\/08\/transp.jpg\" rel=\"lightbox[1107]\"><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-full wp-image-1108\" title=\"transp\" src=\"http:\/\/www.jfdesignnet.com\/wp-content\/uploads\/2010\/08\/transp.jpg\" alt=\"\" width=\"246\" height=\"213\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">One of the most common programs on Linux systems for packaging files  is the venerable tar. tar is short for tape archive, and originally, it  would archive your files to a tape device. Now, you&#8217;re more likely to  use a file to make your archive. To use a tarfile, use the command-line  option -f . To create a new tarfile, use the command-line  option -c. To extract files from a tarfile, use the option -x. You also  can compress the resulting tarfile via two methods. To use bzip2, use  the -j option, or for gzip, use the -z option.<\/p>\n<p style=\"text-align: justify;\">Instead of using a tarfile, you can output your tarfile to stdout or  input your tarfile from stdin by using a hyphen (-). With these options,  you can tar up a directory and all of its subdirectories by using:<\/p>\n<pre>tar cf archive.tar dir\n<\/pre>\n<p>Then, extract it in another directory with:<\/p>\n<pre>tar xf archive.tar\n<\/pre>\n<p>When creating a tarfile, you can assign a volume name with the option -V  . You can move an entire directory structure with tar by  executing:<\/p>\n<pre>tar cf - dir1 | (cd dir2; tar xf -)\n<\/pre>\n<p>You can go even farther and move an entire directory structure over the  network by executing:<\/p>\n<pre>tar cf - dir1 | ssh remote_host \"( cd \/path\/to\/dir2; tar xf - )\"\n<\/pre>\n<p>GNU tar includes an option that lets you skip the cd part, -C  \/path\/to\/dest. You also can interact with tarfiles over the network by  including a host part to the tarfile name. For example:<\/p>\n<pre>tar cvf username@remotehost:\/path\/to\/dest\/archive.tar dir1\n<\/pre>\n<p>This is done by using rsh as the communication mechanism. If you want to  use something else, like ssh, use the command-line option &#8211;rsh-command  CMD. Sometimes, you also may need to give the path to the rmt  executable on the remote host. On some hosts, it won&#8217;t be in the default  location \/usr\/sbin\/rmt. So, all together, this would look like:<\/p>\n<pre>tar -c -v --rsh-command ssh --rmt-command \/sbin\/rmt\n \u21aa-f username@host:\/path\/to\/dest\/archive.tar dir1\n<\/pre>\n<p>Although tar originally used to write its archive to a tape drive, it  can be used to write to any device. For example, if you want to get a  dump of your current filesystem to a secondary hard drive, use:<\/p>\n<pre>tar -cvzf \/dev\/hdd \/\n<\/pre>\n<p>Of course, you need to run the above command as root. If you are writing  your tarfile to a device that is too small, you can tell tar to do a  multivolume archive with the -M option. For those of you who are old  enough to remember floppy disks, you can back up your home directory to a  series of floppy disks by executing:<\/p>\n<pre>tar -cvMf \/dev\/fd0 $HOME\n<\/pre>\n<p>If you are doing backups, you may want to preserve the file permissions.  You can do this with the -p option. If you have symlinked files on your  filesystem, you can dereference the symlinks with the -h option. This  tells tar actually to dump the file that the symlink points to, not just  the symlink.<\/p>\n<p>Along the same lines, if you have several filesystems mounted, you  can tell tar to stick to only one filesystem with the option -l.  Hopefully, this gives you lots of ideas for ways to archive your files.<\/p>\n<p>Found this article come a bit handy and taken from <a href=\"http:\/\/bit.ly\/ca4qn4\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most common programs on Linux systems for packaging files is the venerable tar. tar is short for tape archive, and originally, it would archive your files to a tape device. Now, you&#8217;re more likely to use a file to make your archive. To use a tarfile, use the command-line option -f . [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1108,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[234,235],"_links":{"self":[{"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/posts\/1107"}],"collection":[{"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1107"}],"version-history":[{"count":0,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/posts\/1107\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/media\/1108"}],"wp:attachment":[{"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}