<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.101.0">Hugo</generator><title type="html">tar on A Scripter's Notes</title><subtitle type="html">Emacs, scripting and anything text oriented.</subtitle><link href="https://scripter.co/tags/tar/" rel="alternate" type="text/html" title="HTML"/><link href="https://scripter.co/tags/tar/index.xml" rel="alternate" type="application/rss+xml" title="RSS"/><link href="https://scripter.co/tags/tar/atom.xml" rel="self" type="application/atom+xml" title="Atom"/><link href="https://scripter.co/tags/tar/jf2feed.json" rel="alternate" type="application/jf2feed+json" title="jf2feed"/><updated>2026-04-22T08:24:58-04:00</updated><author><name>Kaushal Modi</name><email>kaushal.modi@gmail.com</email></author><id>https://scripter.co/tags/tar/</id><entry><title type="html">Disarming the 'tar' bomb in 10 seconds</title><link href="https://scripter.co/disarming-the-tar-bomb-in-10-seconds/?utm_source=atom_feed" rel="alternate" type="text/html"/><link href="https://scripter.co/unclutter-a-better-reader-view-for-browsers/?utm_source=atom_feed" rel="related" type="text/html" title="Unclutter: A better Reader View for browsers"/><link href="https://scripter.co/zero-html-validation-errors/?utm_source=atom_feed" rel="related" type="text/html" title="Zero HTML Validation Errors!"/><link href="https://scripter.co/offline-html5-validator/?utm_source=atom_feed" rel="related" type="text/html" title="Offline HTML5 Validator"/><link href="https://scripter.co/hugo-modules-importing-a-theme/?utm_source=atom_feed" rel="related" type="text/html" title="Hugo Modules: Importing a Theme"/><link href="https://scripter.co/looping-through-org-mode-headings/?utm_source=atom_feed" rel="related" type="text/html" title="Looping through Org mode headings"/><id>https://scripter.co/disarming-the-tar-bomb-in-10-seconds/</id><author><name>Kaushal Modi</name></author><published>2022-06-13T01:14:00-04:00</published><updated>2022-06-13T01:14:00-04:00</updated><content type="html"><![CDATA[<blockquote>Use <code>tar -caf &lt;file&gt; &lt;dir&gt;</code> to create an archive, <code>tar -xf &lt;file&gt;</code> to
extract one, and more.</blockquote><div class="ox-hugo-toc toc">
<div class="heading">Table of Contents</div>
<ul>
<li><a href="#mnemonics">Mnemonics</a></li>
<li><a href="#creating-an-archive">Creating an archive</a></li>
<li><a href="#extracting-an-archive">Extracting an archive</a></li>
<li><a href="#listing-contents-of-an-archive">Listing contents of an archive</a></li>
<li><a href="#summary">Summary</a></li>
</ul>
</div>
<!--endtoc-->
<p>I had come across <a href="https://fosstodon.org/@garritfra/108409516362853350">this post by user <em>Garrit</em></a> on Mastodon, and that
inspired this post.</p>
<div class="mf2 reply">In reply to: <p><a class="u-in-reply-to h-cite" rel="in-reply-to" href="https://garrit.xyz/posts/2022-06-02-tar-commands">https://garrit.xyz/posts/2022-06-02-tar-commands</a></p></div>
<p>A post on the Unix command <a href="https://www.gnu.org/software/tar/manual/html_node/index.html" title="Emacs Lisp: (info &quot;(tar) Top&quot;)"><code>tar</code></a> cannot leave out the obligatory <em>xkcd
<strong>tar</strong></em> comic 😄, so here it is:</p>
<p><a id="figure--xkcd-1168"></a></p>



<figure>
    
        <img src="https://scripter.co/disarming-the-tar-bomb-in-10-seconds/xkcd-1168.png" title="I don't know what's worse--the fact that after 15 years of using tar I still can't keep the flags straight, or that after 15 years of technological advancement I'm still mucking with tar flags that were 15 years old when I started."/> <figcaption>
                <p>
                    
                    <a href="https://xkcd.com/1168/"> 
                        xkcd.com
                        </a></p>
                
            </figcaption></figure>


<h2 id="mnemonics">Mnemonics&nbsp;<a class="headline-hash no-text-decoration" href="#mnemonics">#</a></h2>


<p>These few mnemonics help me remember the basic and my most frequently
used <code>tar</code> options:</p>
<ul>
<li><strong>c</strong> to (c)reate</li>
<li><strong>a</strong> to (a)uto compress the archive based on the file name</li>
<li><strong>x</strong> to e(x)tract</li>
<li><strong>f</strong> for the archive (f)ile name we are dealing with (whether
creating, listing or extracting an archive)</li>
</ul>
<p>.. and a few not so frequent options (for me):</p>
<ul>
<li><strong>t</strong> to lis(t) contents of an archive</li>
<li><strong>v</strong> for (v)erbose output</li>
</ul>

<h2 id="creating-an-archive">Creating an archive&nbsp;<a class="headline-hash no-text-decoration" href="#creating-an-archive">#</a></h2>


<div class="org-center">
<p><strong>tar -caf &lt;file&gt; &lt;dir&gt;</strong></p>
</div>
<p>A keen user might have noticed that I am using <code>tar -caf ..</code> instead
of <code>tar caf ..</code> i.e. I am using a hyphen before the <code>tar</code>
options. Both approaches work and they look similar, but the approach
with the hyphen is the <strong>newer</strong> <a href="https://www.gnu.org/software/tar/manual/html_node/Short-Options.html" title="Emacs Lisp: (info &quot;(tar) Short Options&quot;)">Short Option style</a> while the other is
the <a href="https://www.gnu.org/software/tar/manual/html_node/Old-Options.html" title="Emacs Lisp: (info &quot;(tar) Old Options&quot;)">Old Option style</a>.</p>
<div class="note">
<p>I prefer the <em>short option style</em> because .. well.. the other style is
old.. and also because the <em>short option style</em> is <strong>stricter</strong> e.g. the
<code>-f</code> switch has to be followed by the file name.</p>
</div>
<p>Whether you are creating a regular <strong>.tar</strong> archive, or a compressed
archive like <strong>.tar.gz</strong>, always use the auto-compresion switch
<strong>-a</strong>. That relieves you from deciding <em>if</em> you need that switch, or
which compression algorithm switch should be used 😄.</p>
<p>The <strong>-a</strong> switch makes the decision for you based on the file
extension.  For example, <code>tar -caf foo.tar foo/</code> will create a regular
archive, while <code>tar -caf foo.tar.gz foo/</code> will create a compressed
archive using <code>gzip</code>. You can read more about it in <a href="https://www.gnu.org/software/tar/manual/html_node/gzip.html" title="Emacs Lisp: (info &quot;(tar) gzip&quot;)">Creating and
Reading Compressed Archives</a>.</p>

<h2 id="extracting-an-archive">Extracting an archive&nbsp;<a class="headline-hash no-text-decoration" href="#extracting-an-archive">#</a></h2>


<div class="org-center">
<p><strong>tar -xf &lt;file&gt;</strong></p>
</div>
<p>At times, it might be useful to add the verbosity switch <strong>-v</strong> to this
command and do <code>tar -xvf &lt;file&gt;</code>.</p>
<div class="note">
<p>Just to reiterate, the <strong>-f</strong> switch must be followed by the archive
file name.</p>
</div>

<h2 id="listing-contents-of-an-archive">Listing contents of an archive&nbsp;<a class="headline-hash no-text-decoration" href="#listing-contents-of-an-archive">#</a></h2>


<div class="org-center">
<p><strong>tar -tf &lt;file&gt;</strong></p>
</div>
<p>Once you are done creating an archive, you might feel the need to
check if the archive contains everything you expect. Or you might want
to check what&rsquo;s inside the archive before you extract it.</p>
<p>This command is often paired with <code>grep</code> or <a href="https://github.com/BurntSushi/ripgrep"><code>rg</code> (ripgrep)</a> like so:
<code>tar -tf foo.tar.xz | rg 'some_file_name_in_archive'</code>.</p>

<h2 id="summary">Summary&nbsp;<a class="headline-hash no-text-decoration" href="#summary">#</a></h2>


<p>If you simply glossed over the whole article, or didn&rsquo;t read through
the all linked manual pages
<span class="sidenote-number"><small class="sidenote">
I know you didn&rsquo;t 😉
</small></span>
, just remember this &mdash;</p>
<div class="org-center">
<p><strong>tar -caf</strong> to <strong>c</strong>​reate and <strong>tar -xf</strong> to e​<strong>x</strong>​tract</p>
</div>
]]></content><category scheme="https://scripter.co/categories/unix" term="unix" label="unix"/><category scheme="https://scripter.co/categories/replies" term="replies" label="replies"/><category scheme="https://scripter.co/tags/tar" term="tar" label="tar"/><category scheme="https://scripter.co/tags/100daystooffload" term="100daystooffload" label="100DaysToOffload"/></entry></feed>