TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Extract it – Because nobody can remember tar commands

27 pointsby mawaluover 9 years ago

21 comments

kazinatorover 9 years ago
It&#x27;s a nice web gadget. However, I just go by this handy table, which is on a yellow stickie on my monitor:<p><pre><code> NAME MODERN GNU TAR COMMAND file.tar.gz tar xf file.tar.gz file.tar.bz tar xf file.tar.bz file.tar.bz2 tar xf file.tar.bz2 file.tar tar xf file.tar file.tgz tar xf file.tgz (missing from web gadget!) file.abcdef tar xv file.abcdf (*) --- * If file.abcdf is actually any of the preceding formats; i.e. GNU Tar doesn&#x27;t just go by the suffix! </code></pre> Nobody memorizes these, and I wouldn&#x27;t want to turn into a nobody, right?<p>By the way, if you actually do need a command which performs a pattern match on a file name and dispatches some other command, why would you go through a web browser? You&#x27;d want this in your shell as a function:<p><pre><code> $ dtrt x.blorch.zonk.bloop # &quot;do the right thing&quot; </code></pre> Hello, we have &quot;case&quot;<p><pre><code> case &quot;$file&quot; in -* | --* ) echo &quot;oops, $file looks like an option!&quot; ;; *.zip ) unzip &quot;$file&quot; ;; *.rar ) ... ;; *.tar.* | *.tgz | *.tar ) tar xf &quot;$file&quot; ;; ... esac</code></pre>
quantumtremorover 9 years ago
Just add this to your .bashrc&#x2F;.zshrc.<p><pre><code> extract () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo &quot;&#x27;$1&#x27; cannot be extracted via ex()&quot; ;; esac else echo &quot;&#x27;$1&#x27; is not a valid file&quot; fi }</code></pre>
评论 #10201443 未加载
评论 #10201454 未加载
评论 #10201484 未加载
gfodorover 9 years ago
Why not just learn what the flags mean? If you&#x27;re cargo culting it, and not learning the point of the &quot;xfvz&quot; (it means eXtract, from the specified File, with a Visual dump of the extraction, from a gZipped archived tarball) -- you&#x27;ll never remember it.
评论 #10201447 未加载
评论 #10201449 未加载
评论 #10201482 未加载
评论 #10201400 未加载
评论 #10201399 未加载
Splognosticusover 9 years ago
For GNU tar at least it&#x27;s not necessary to specify the compression program when extracting--it will auto-detect it. Additionally when creating tar files it has -a, --auto-compress to use the file extension to determine the compression program to use.<p><a href="http:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;tar&#x2F;manual&#x2F;html_node&#x2F;gzip.html#auto_002dcompress" rel="nofollow">http:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;tar&#x2F;manual&#x2F;html_node&#x2F;gzip.html#a...</a>
评论 #10201247 未加载
guessmynameover 9 years ago
I have good memory but I always try to convert information into mental cards so I can draw associations, that is how I have learned all commands you can imagine. I deactivated the system file manager of my operation system long time ago because I got used to the terminal, and that is how I do everything in my personal computer.<p>For extraction of archives I am able to remember the commands like this. For files with &quot;tar&quot; extension I use &quot;tar xf&quot; (where &quot;x&quot; means eXtract and &quot;f&quot; file, I think so). Now, if the extension is &quot;tar.bz2&quot; add a &quot;j&quot;, and &quot;z&quot; for &quot;tar.gz&quot;. For &quot;zip&quot; files use &quot;unzip&quot; and start adding a prefix like &quot;b&quot; or &quot;g&quot; for &quot;bz2&quot; and &quot;gz&quot; files respectively:<p><pre><code> file.tar -&gt; tar xf file.tar.gz -&gt; tar xfz file.tar.bz2 -&gt; tar xfj file.zip -&gt; unzip file.bz2 -&gt; bunzip2 file.gz -&gt; gunzip </code></pre> <a href="https:&#x2F;&#x2F;github.com&#x2F;xvoland&#x2F;Extract" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;xvoland&#x2F;Extract</a>
mahouseover 9 years ago
Does not recognise .xz? It&#x27;s the first thing I tried, ffs.<p>It looks like it does not recognise other usual things such as .gz alone or .tgz: <a href="https:&#x2F;&#x2F;github.com&#x2F;Mawalu&#x2F;extract-it&#x2F;blob&#x2F;gh-pages&#x2F;main.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Mawalu&#x2F;extract-it&#x2F;blob&#x2F;gh-pages&#x2F;main.js</a>
评论 #10201223 未加载
评论 #10201162 未加载
jamiesonbeckerover 9 years ago
Or, add this to your .bashrc (ensure that it&#x27;s sourced.. some distributions don&#x27;t do this automatically):<p><pre><code> alias untar=&quot;tar xvf&quot; </code></pre> Then, open a new terminal window, and from then on it&#x27;s just:<p><pre><code> untar filename.tar.gz</code></pre>
评论 #10201392 未加载
txutxuover 9 years ago
Does not work if I don&#x27;t use a dot at the beginning of the extension.<p><pre><code> .tar -&gt; enter -&gt; works tar -&gt; enter -&gt; nothing happens </code></pre> I use an extract() function on my shell initialization files. It deals with most formats for me.<p>Anyway nice to see it implemented on a web interface, the source code is really brief :-)<p>Right now it supports tar, tar.gz, tar.bz, tar.bz2 and zip. If you want to deal with more formats, you have plenty of places to look for the &#x27;ext =&gt; cmd&#x27; relation:<p><pre><code> https:&#x2F;&#x2F;github.com&#x2F;search?q=extract</code></pre>
评论 #10201164 未加载
anthonyuover 9 years ago
I can remember tar commands.
robalfonsoover 9 years ago
Maybe I just use tar a lot, but I actually can remember all the flags I typically use and wouldn&#x27;t use this :) still nice work though.<p>co workers have sent this to me multiple times<p><a href="https:&#x2F;&#x2F;xkcd.com&#x2F;1168&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xkcd.com&#x2F;1168&#x2F;</a><p>it helps the characters name is also mine!
carlosf8over 9 years ago
I use atool (<a href="http:&#x2F;&#x2F;www.nongnu.org&#x2F;atool&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.nongnu.org&#x2F;atool&#x2F;</a>) You can just do &quot;aunpack file&quot; or &quot;atool -x file&quot;, same goes for packing..
评论 #10201401 未加载
madpropsover 9 years ago
Why hasn&#x27;t anyone made (afaik) an all in one extractor that depends on all the popular compression tools and uses the appropriate one depending on the extension. That would be useful.
评论 #10201232 未加载
评论 #10201442 未加载
评论 #10201489 未加载
评论 #10201382 未加载
ben0x539over 9 years ago
Gee, I&#x27;ve been using a handrolled program that a) figures out what other program to delegate to as well as what options to pass and b) makes sure unpacking whatever results in exactly one new entry in the current directory, that is, unpacks into a newly created directory if there&#x27;s more than one thing top-level in the archive. Maybe I should have been posting it on the internet!
keithgabryelskiover 9 years ago
You basically need to know three options for tar:<p>-x EXTRACT -c CREATE -f - USE STDIN&#x2F;OUT<p>to create a tar file of the current directory:<p>tar -cf - . | gzip &gt; &#x2F;tmp&#x2F;foo.tar.gz<p>to extract:<p>gzip &lt; &#x2F;tmp&#x2F;foo.tar.gz | tar -xf -<p>why tar has all the options was someone&#x27;s idea they were helping you out -- they weren&#x27;t<p>Create is -c --- remember that eXtract is -x - remember that -f - is stdout&#x2F;stdin depending on your need -- remember that<p>pipes are your friend.
nickgartmannover 9 years ago
I use a little mnemonic phrase... tar dash eXtract Zee Files (tar -xzf)<p>and<p>tar dash Compress Zee Files (tar -czf)<p>Yes, the z does nothing when extracting. But it helps me remember.
crimsonalucardover 9 years ago
This makes total sense as a web service.<p>In all seriousness... why? This would be an awesome unix tool.
评论 #10201227 未加载
mpnordlandover 9 years ago
Every time I need to extract some kind of tar file i just do tar -xf filename.tar.&lt;whatever&gt; and it works fine. This would be nice for compressing, but seems pointless.
mydpyover 9 years ago
Wait, is this seriously a problem for people, or an xkcd joke?
retrogradeorbitover 9 years ago
In all seriousness, who would actually use this?
jfbover 9 years ago
I&#x27;m not using this until it handles SGI bru. Remember bru? No? Consider yourself lucky.
tetraodonpufferover 9 years ago
what other tar commands&#x2F;options do people use when extracting? lately with tar it doesn&#x27;t even seem you need z&#x2F;J&#x2F;... to pick the compression format, just tar xvf archive.tar.whatever and it figures it out itself