It'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't just go by the suffix!
</code></pre>
Nobody memorizes these, and I wouldn'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'd want this in your shell as a function:<p><pre><code> $ dtrt x.blorch.zonk.bloop # "do the right thing"
</code></pre>
Hello, we have "case"<p><pre><code> case "$file" in
-* | --* ) echo "oops, $file looks like an option!" ;;
*.zip ) unzip "$file" ;;
*.rar ) ... ;;
*.tar.* | *.tgz | *.tar ) tar xf "$file" ;;
...
esac</code></pre>
Just add this to your .bashrc/.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 "'$1' cannot be extracted via ex()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}</code></pre>
Why not just learn what the flags mean? If you're cargo culting it, and not learning the point of the "xfvz" (it means eXtract, from the specified File, with a Visual dump of the extraction, from a gZipped archived tarball) -- you'll never remember it.
For GNU tar at least it'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://www.gnu.org/software/tar/manual/html_node/gzip.html#auto_002dcompress" rel="nofollow">http://www.gnu.org/software/tar/manual/html_node/gzip.html#a...</a>
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 "tar" extension I use "tar xf" (where "x" means eXtract and "f" file, I think so). Now, if the extension is "tar.bz2" add a "j", and "z" for "tar.gz". For "zip" files use "unzip" and start adding a prefix like "b" or "g" for "bz2" and "gz" files respectively:<p><pre><code> file.tar -> tar xf
file.tar.gz -> tar xfz
file.tar.bz2 -> tar xfj
file.zip -> unzip
file.bz2 -> bunzip2
file.gz -> gunzip
</code></pre>
<a href="https://github.com/xvoland/Extract" rel="nofollow">https://github.com/xvoland/Extract</a>
Does not recognise .xz? It'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://github.com/Mawalu/extract-it/blob/gh-pages/main.js" rel="nofollow">https://github.com/Mawalu/extract-it/blob/gh-pages/main.js</a>
Or, add this to your .bashrc (ensure that it's sourced.. some distributions don't do this automatically):<p><pre><code> alias untar="tar xvf"
</code></pre>
Then, open a new terminal window, and from then on it's just:<p><pre><code> untar filename.tar.gz</code></pre>
Does not work if I don't use a dot at the beginning of the extension.<p><pre><code> .tar -> enter -> works
tar -> enter -> 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 'ext => cmd' relation:<p><pre><code> https://github.com/search?q=extract</code></pre>
Maybe I just use tar a lot, but I actually can remember all the flags I typically use and wouldn't use this :) still nice work though.<p>co workers have sent this to me multiple times<p><a href="https://xkcd.com/1168/" rel="nofollow">https://xkcd.com/1168/</a><p>it helps the characters name is also mine!
I use atool (<a href="http://www.nongnu.org/atool/" rel="nofollow">http://www.nongnu.org/atool/</a>)
You can just do "aunpack file" or "atool -x file", same goes for packing..
Why hasn'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.
Gee, I'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's more than one thing top-level in the archive. Maybe I should have been posting it on the internet!
You basically need to know three options for tar:<p>-x EXTRACT
-c CREATE
-f - USE STDIN/OUT<p>to create a tar file of the current directory:<p>tar -cf - . | gzip > /tmp/foo.tar.gz<p>to extract:<p>gzip < /tmp/foo.tar.gz | tar -xf -<p>why tar has all the options was someone's idea they were helping you out -- they weren't<p>Create is -c --- remember that
eXtract is -x - remember that
-f - is stdout/stdin depending on your need -- remember that<p>pipes are your friend.
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.
Every time I need to extract some kind of tar file i just do tar -xf filename.tar.<whatever> and it works fine. This would be nice for compressing, but seems pointless.
what other tar commands/options do people use when extracting? lately with tar it doesn't even seem you need z/J/... to pick the compression format, just tar xvf archive.tar.whatever and it figures it out itself