News for hackers. Stuff that matters.
Re:Show HN: Extract it – Because nobody can remember tar com... by kazinator on Thursday September 10, 2015 @08:31PM (#10201364)
It's a nice web gadget. However, I just go by this handy table, which is on a yellow stickie on my monitor:

  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!
Nobody memorizes these, and I wouldn't want to turn into a nobody, right?

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:

  $ dtrt x.blorch.zonk.bloop # "do the right thing"
Hello, we have "case"

  case "$file" in
  -* | --* ) echo "oops, $file looks like an option!" ;;
  *.zip ) unzip "$file" ;;
  *.rar ) ... ;;
  *.tar.* | *.tgz | *.tar ) tar xf "$file" ;;
  ...
  esac
Re:Show HN: Extract it – Because nobody can remember tar com... by quantumtremor on Thursday September 10, 2015 @08:50PM (#10201422)
Just add this to your .bashrc/.zshrc.

  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  
  }
Re:Show HN: Extract it – Because nobody can remember tar com... by ryenus on Thursday September 10, 2015 @08:54PM (#10201443)
all the $1 here should be quoted as "$1", just in case if it gets a file with space in the name.
Re:Show HN: Extract it – Because nobody can remember tar com... by indiv0 on Thursday September 10, 2015 @08:59PM (#10201454)
Re:Show HN: Extract it – Because nobody can remember tar com... by snorrah on Thursday September 10, 2015 @09:11PM (#10201484)
If you have 7z, do you need most of the others? 7z seems like it might process all of the others listed here.
Re:Show HN: Extract it – Because nobody can remember tar com... by gfodor on Thursday September 10, 2015 @08:32PM (#10201366)
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.
Re:Show HN: Extract it – Because nobody can remember tar com... by reedlaw on Thursday September 10, 2015 @08:55PM (#10201447)
"tar xvzf" is already a part of my muscle memory. Occasionally I need to change the "z" to a "j" for bzip2 archives. And the "x" becomes a "c" if I'm Creating an archive rather than eXtracting.

Also this site doesn't show the command for files with ".tgz" extensions.

Re:Show HN: Extract it – Because nobody can remember tar com... by JoshTriplett on Thursday September 10, 2015 @08:57PM (#10201450)
> tar xvzf" is already a part of my muscle memory. Occasionally I need to change the "z" to a "j" for bzip2 archives

With modern tar, just don't include the z at all. "tar -xf" knows how to extract various kinds of compressed tar files automatically.

Re:Show HN: Extract it – Because nobody can remember tar com... by monksy on Thursday September 10, 2015 @09:06PM (#10201469)
Today I learned. I've been doing zxvf for quite a while and I always got annoyed with bz2 files.
Re:Show HN: Extract it – Because nobody can remember tar com... by nstart on Thursday September 10, 2015 @08:56PM (#10201449)
Yeps. I used to have to keep googling whenever I wanted to extract something. Then I decided to learn what the flags meant and realised how easy it was. When doing the command it was a matter of saying it in head ("I am extracting from this gzipped file"). Likewise for compressing. Only difference being 'c' stood for Compressing.
Re:Show HN: Extract it – Because nobody can remember tar com... by deciplex on Thursday September 10, 2015 @09:10PM (#10201482)
You adding a lot of extra words, and there are many other options to tar, and you've left out making an archive, but yeah:

-cf Create File -xf eXtract File

then you have the adverb v, and the adjective z:

-vczf Verbosely Create gZip File -vxzf Verbosely eXtract gZip File

I find it difficult to remember the arguments mostly because I seldom use tar, not because the arguments are unintuitive or something.

Re:Show HN: Extract it – Because nobody can remember tar com... by Hello71 on Thursday September 10, 2015 @08:43PM (#10201400)
no, "v" means verbose since at least 2.8 BSD: https://www.freebsd.org/cgi/man.cgi?query=tar&manpath=2.8+BS...
[deleted]
Re:Show HN: Extract it – Because nobody can remember tar com... by adrusi on Thursday September 10, 2015 @08:58PM (#10201451)
The f isn't for force. It's for "file" and it takes the filename as a parameter — that's why you usually see it at the end of the character sequence, a filename has to immediately follow it. If you don't specify -f tar will read from stdin for extraction or write to stdout for creation.
Re:Show HN: Extract it – Because nobody can remember tar com... by SeldomSoup on Friday September 11, 2015 @12:06AM (#10201960)
Seems like a redundant flag. Many utilities are perfectly fine reading from stdin if no [file] is specified, without any kind of -f flag.
Re:Show HN: Extract it – Because nobody can remember tar com... by adrusi on Friday September 11, 2015 @08:43AM (#10203319)
It's redundant for extraction. For creation (-c) where you can list many files, it's just a choice some unix developer made to allow the destination file to be specified independent of order. I think there'd be some awkward edge cases otherwise.

Anyway, adding verbosity to discourage operating on static files and prefering being on a pipeline could be considered a feature.

Re:Show HN: Extract it – Because nobody can remember tar com... by Splognosticus on Thursday September 10, 2015 @07:44PM (#10201236)
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.

http://www.gnu.org/software/tar/manual/html_node/gzip.html#a...

Re:Show HN: Extract it – Because nobody can remember tar com... by spartas on Thursday September 10, 2015 @07:48PM (#10201247)
Recent versions of BSD tar will also detect the compression algorithm for extracting. No such luck with the -a, --auto-compress option though.
Re:Show HN: Extract it – Because nobody can remember tar com... by craftkiller on Thursday September 10, 2015 @08:42PM (#10201393)
Bsdtar definitely supports -a. I'm on a phone so I can't help too much but its the first option after you Ctrl+f for getopt on https://github.com/libarchive/libarchive/blob/master/tar/bsd...
Re:Show HN: Extract it – Because nobody can remember tar com... by guessmyname on Thursday September 10, 2015 @08:26PM (#10201353)
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.

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:

  file.tar     -> tar xf
  file.tar.gz  -> tar xfz
  file.tar.bz2 -> tar xfj
  file.zip     ->  unzip
  file.bz2     -> bunzip2
  file.gz      -> gunzip
https://github.com/xvoland/Extract
Re:Show HN: Extract it – Because nobody can remember tar com... by mahouse on Thursday September 10, 2015 @06:51PM (#10201048)
Does not recognise .xz? It's the first thing I tried, ffs.

It looks like it does not recognise other usual things such as .gz alone or .tgz: https://github.com/Mawalu/extract-it/blob/gh-pages/main.js

Re:Show HN: Extract it – Because nobody can remember tar com... by scintill76 on Thursday September 10, 2015 @07:41PM (#10201223)

    var input = document.querySelector('#leInput'),
    commands = {
      '.tar': 'tar xfv',
      '.zip': 'unzip',
      '.tar.bz2': 'tar jxvf',
      '.tar.gz': 'tar xfvz',
      '.tar.bz': 'tar xjf',
    };
I don't think the difference between .bz2 and .bz makes any sense. Am I wrong, or is it just that bz2 extracts verbosely and bz doesn't? I'd guess these flags were copied from some random sources without the author realizing they are nearly equivalent.

I know difficulty with tar is a meme[1], but once you get over that "j" means bz2, why is it hard to remember V for Verbose, Z for gZip, X for eXtract, F for File (which you'll almost always be passing)? I ask this both rhetorically because it shouldn't be hard, but also because I am sometimes oddly hesitant when forming tar commands. But not enough to reach for a web page.

[1] https://xkcd.com/1168/

Re:Show HN: Extract it – Because nobody can remember tar com... by mahouse on Friday September 11, 2015 @06:02AM (#10202854)
It's not hard at all. I personally memorised "zxvf", and change z accordingly, or remove v if it's a shitload of files and it floods my terminal.
Re:Show HN: Extract it – Because nobody can remember tar com... by redwards510 on Thursday September 10, 2015 @07:24PM (#10201162)
That's the first thing I tried too. I thought the site was broken because there's no button to push and after hitting enter nothing happened. It's ok if you don't support everything yet, but at least have a message saying "Not yet implemented" or something, please.
Re:Show HN: Extract it – Because nobody can remember tar com... by jamiesonbecker on Thursday September 10, 2015 @07:48PM (#10201242)
Or, add this to your .bashrc (ensure that it's sourced.. some distributions don't do this automatically):

     alias untar="tar xvf"

Then, open a new terminal window, and from then on it's just:

     untar filename.tar.gz
Re:Show HN: Extract it – Because nobody can remember tar com... by archinal on Thursday September 10, 2015 @08:41PM (#10201392)
Don't you need the z flag as well since filename is gzipped?
Re:Show HN: Extract it – Because nobody can remember tar com... by jamiesonbecker on Thursday September 10, 2015 @09:26PM (#10201520)
Not anymore! GNU tar now figures it out automagically :)
Re:Show HN: Extract it – Because nobody can remember tar com... by oofabz on Thursday September 10, 2015 @11:58PM (#10201943)
BSD tar also has this functionality. "tar -xf <filename>" works for archives compressed with gzip, bzip2, or xz.
Re:Show HN: Extract it – Because nobody can remember tar com... by txutxu on Thursday September 10, 2015 @06:59PM (#10201076)
Does not work if I don't use a dot at the beginning of the extension.

    .tar -> enter -> works
    tar  -> enter -> nothing happens

I use an extract() function on my shell initialization files. It deals with most formats for me.

Anyway nice to see it implemented on a web interface, the source code is really brief :-)

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:

     https://github.com/search?q=extract
Re:Show HN: Extract it – Because nobody can remember tar com... by madprops on Thursday September 10, 2015 @07:25PM (#10201164)
>Does not work if I don't use a dot at the beginning of the extension.

Maybe because you're expected to type the full filename, for example crash34_master.tar.gz

Re:Show HN: Extract it – Because nobody can remember tar com... by anthonyu on Thursday September 10, 2015 @07:34PM (#10201193)
I can remember tar commands.
Re:Show HN: Extract it – Because nobody can remember tar com... by robalfonso on Thursday September 10, 2015 @08:19PM (#10201331)
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.

co workers have sent this to me multiple times

https://xkcd.com/1168/

it helps the characters name is also mine!

Re:Show HN: Extract it – Because nobody can remember tar com... by carlosf8 on Thursday September 10, 2015 @07:48PM (#10201245)
I use atool (http://www.nongnu.org/atool/) You can just do "aunpack file" or "atool -x file", same goes for packing..
Re:Show HN: Extract it – Because nobody can remember tar com... by vortico on Thursday September 10, 2015 @08:44PM (#10201401)
I've used this for years, not because I can't remember tar, gunzip, unzip, unrar, 7z, etc commands (although it takes a second to recall which flags to use for a particular archive format), but because it prevents tarbombs/zipbombs from filling my current working directory. It first extracts the archive to a temporary folder, and if it notices only one file in the folder, it moves it back one directory. One minor complaint is that "aunpack" is awkward to type, so I've aliased it to `a`.
Re:Show HN: Extract it – Because nobody can remember tar com... by madprops on Thursday September 10, 2015 @07:42PM (#10201225)
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.
Re:Show HN: Extract it – Because nobody can remember tar com... by cperciva on Thursday September 10, 2015 @07:43PM (#10201232)
bsdtar does this, except by looking at the file format rather than looking at the extension. It supports tar, pax, cpio, zip, xar, lha, ar, cab, mtree, rar, and ISO images, compressed using gzip, bzip2, lzip, xz, lzma, or compress.
Re:Show HN: Extract it – Because nobody can remember tar com... by adrusi on Thursday September 10, 2015 @08:53PM (#10201442)
It's called tar. Seriously. I'm positive gnu tar will pick the compression engine based on the file contents, I think bsd does too. It's not a documented standard, but if all implementations support it, it may as well be.
Re:Show HN: Extract it – Because nobody can remember tar com... by tetron on Thursday September 10, 2015 @09:13PM (#10201489)
Someone has, it is called dtrx ("do the right thing extractor"):

http://brettcsmith.org/2007/dtrx/

Re:Show HN: Extract it – Because nobody can remember tar com... by kw71 on Thursday September 10, 2015 @08:39PM (#10201382)
7zip does most of them, but doesn't depend on the original tools.
Re:Show HN: Extract it – Because nobody can remember tar com... by ben0x539 on Saturday September 12, 2015 @04:08PM (#10209166)
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!
Re:Show HN: Extract it – Because nobody can remember tar com... by keithgabryelski on Thursday September 10, 2015 @09:51PM (#10201578)
You basically need to know three options for tar:

-x EXTRACT -c CREATE -f - USE STDIN/OUT

to create a tar file of the current directory:

tar -cf - . | gzip > /tmp/foo.tar.gz

to extract:

gzip < /tmp/foo.tar.gz | tar -xf -

why tar has all the options was someone's idea they were helping you out -- they weren't

Create is -c --- remember that eXtract is -x - remember that -f - is stdout/stdin depending on your need -- remember that

pipes are your friend.

Re:Show HN: Extract it – Because nobody can remember tar com... by nickgartmann on Thursday September 10, 2015 @08:27PM (#10201354)
I use a little mnemonic phrase... tar dash eXtract Zee Files (tar -xzf)

and

tar dash Compress Zee Files (tar -czf)

Yes, the z does nothing when extracting. But it helps me remember.

Re:Show HN: Extract it – Because nobody can remember tar com... by crimsonalucard on Thursday September 10, 2015 @07:41PM (#10201221)
This makes total sense as a web service.

In all seriousness... why? This would be an awesome unix tool.

Re:Show HN: Extract it – Because nobody can remember tar com... by gue5t on Thursday September 10, 2015 @07:42PM (#10201227)
One such unix tool is "dtrx", which has been around for ages.

http://freecode.com/projects/dtrx

Re:Show HN: Extract it – Because nobody can remember tar com... by oofabz on Thursday September 10, 2015 @09:13PM (#10201488)
I use p7zip, which has also been around for ages. Whether you have a .tgz, .txz, .rar, .zip, or whatever, you can extract it with "7z x <filename>".
Re:Show HN: Extract it – Because nobody can remember tar com... by mpnordland on Thursday September 10, 2015 @07:44PM (#10201233)
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.
Re:Show HN: Extract it – Because nobody can remember tar com... by mydpy on Thursday September 10, 2015 @09:15PM (#10201494)
Wait, is this seriously a problem for people, or an xkcd joke?
Re:Show HN: Extract it – Because nobody can remember tar com... by retrogradeorbit on Thursday September 10, 2015 @08:31PM (#10201363)
In all seriousness, who would actually use this?
Re:Show HN: Extract it – Because nobody can remember tar com... by jfb on Thursday September 10, 2015 @08:32PM (#10201365)
I'm not using this until it handles SGI bru. Remember bru? No? Consider yourself lucky.
Re:Show HN: Extract it – Because nobody can remember tar com... by tetraodonpuffer on Thursday September 10, 2015 @07:43PM (#10201229)
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