<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:foaf="https://xmlns.com/foaf/0.1/" xmlns:og="https://ogp.me/ns#" xmlns:rdfs="https://www.w3.org/2000/01/rdf-schema#" xmlns:schema="https://schema.org/" xmlns:sioc="https://rdfs.org/sioc/ns#" xmlns:sioct="https://rdfs.org/sioc/types#" xmlns:skos="https://www.w3.org/2004/02/skos/core#" xmlns:xsd="https://www.w3.org/2001/XMLSchema#" version="2.0" xml:base="https://www.linuxjournal.com/tag/tar">
  <channel>
    <title>tar</title>
    <link>https://www.linuxjournal.com/tag/tar</link>
    <description/>
    <language>en</language>
    
    <item>
  <title>Stupid tar Tricks</title>
  <link>https://www.linuxjournal.com/content/stupid-tar-tricks</link>
  <description>  &lt;div data-history-node-id="1011890" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-field-node-image field--type-image field--label-hidden field--item"&gt;  &lt;img src="https://www.linuxjournal.com/sites/default/files/nodeimage/story/43-29-2010%207-25-49%20PM.png" width="240" height="152" alt="" typeof="foaf:Image" class="img-responsive" /&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/user/800005" lang="" about="https://www.linuxjournal.com/user/800005" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;LJ Staff&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;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'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.&lt;/p&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;pre&gt;
tar cf archive.tar dir
&lt;/pre&gt;&lt;p&gt;
Then, extract it in another directory with:&lt;/p&gt;
&lt;pre&gt;
tar xf archive.tar
&lt;/pre&gt;&lt;p&gt;
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:&lt;/p&gt;
&lt;pre&gt;
tar cf - dir1 | (cd dir2; tar xf -)
&lt;/pre&gt;&lt;p&gt;
You can go even farther and move an entire directory structure over the network by executing:&lt;/p&gt;
&lt;pre&gt;
tar cf - dir1 | ssh remote_host "( cd /path/to/dir2; tar xf - )"
&lt;/pre&gt;&lt;p&gt;
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:&lt;/p&gt;
&lt;pre&gt;
tar cvf username@remotehost:/path/to/dest/archive.tar dir1
&lt;/pre&gt;&lt;p&gt;
This is done by using rsh as the communication mechanism. If you want to use something else, like ssh, use the command-line option --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't be in the default location /usr/sbin/rmt. So, all together, this would look like:&lt;/p&gt;
&lt;pre&gt;
tar -c -v --rsh-command ssh --rmt-command /sbin/rmt 
 ↪-f username@host:/path/to/dest/archive.tar dir1
&lt;/pre&gt;&lt;p&gt;
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:&lt;/p&gt;
&lt;pre&gt;
tar -cvzf /dev/hdd /
&lt;/pre&gt;&lt;p&gt;
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:&lt;/p&gt;
&lt;pre&gt;
tar -cvMf /dev/fd0 $HOME
&lt;/pre&gt;&lt;p&gt;
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.&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/stupid-tar-tricks" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Thu, 26 Aug 2010 14:00:00 +0000</pubDate>
    <dc:creator>LJ Staff</dc:creator>
    <guid isPermaLink="false">1011890 at https://www.linuxjournal.com</guid>
    </item>

  </channel>
</rss>
