1168: "Tar"

This forum is for the individual discussion thread that goes with each new comic.

Moderators: Moderators General, Prelates, Magistrates

Drooling Iguana
Posts: 29
Joined: Tue Jun 05, 2007 12:41 am UTC

1168: "Tar"

Postby Drooling Iguana » Fri Feb 01, 2013 5:12 am UTC

Image

Title text: 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.

~ $tar -zxf foo.tar.gz

How hard is that?

User avatar
Marios101Cool
Posts: 12
Joined: Sun Jul 04, 2010 10:58 pm UTC

Re: 1168: Tar

Postby Marios101Cool » Fri Feb 01, 2013 5:14 am UTC

Man you're fast! I almost had mine posted before I checked here.

I must say though... we'd all be dead if I were disarming the bomb, too. I can never keep the damn flags straight, either.
Image
I'm surprised that I got more history than computers. I guess it's because I don't recognize microprocessors on sight and I don't mess around with 512KB RAM computers?

User avatar
rwald
Posts: 153
Joined: Mon Jan 29, 2007 7:14 am UTC
Contact:

Re: 1168: Tar

Postby rwald » Fri Feb 01, 2013 5:15 am UTC

I immediately thought "tar -xvf my_file_name.tar.gz"; I'm not seeing the challenge, here.

User avatar
glasnt
Posts: 539
Joined: Fri Jan 25, 2008 5:18 am UTC
Location: SQUEE!

Re: 1168: Tar

Postby glasnt » Fri Feb 01, 2013 5:15 am UTC

Well, isn't this comic a ball of laughs.

Spoiler:
tar ball.. tarball.

User avatar
plin25
Posts: 36
Joined: Fri Dec 19, 2008 5:32 am UTC
Location: Lost in my mind
Contact:

Re: 1168: Tar

Postby plin25 » Fri Feb 01, 2013 5:16 am UTC

tar -xvf never works for me, I always use tar xvf, but when creating it's tar -cvf...
´¯`·.¸¸.·´¯`·.¸ }<((((((º>

Varriount
Posts: 14
Joined: Sun Aug 12, 2012 8:14 am UTC

Re: 1168: Tar

Postby Varriount » Fri Feb 01, 2013 5:19 am UTC

Don't forget the 5 or so other archive/zip programs, each with their own unique flag combinations.
Can't there be some sort of standardization?
*Prepares for incoming attacks from Linux Pros*

User avatar
rhomboidal
Posts: 759
Joined: Wed Jun 15, 2011 5:25 pm UTC
Contact:

Re: 1168: Tar

Postby rhomboidal » Fri Feb 01, 2013 5:20 am UTC

It's just SO inconvenient blowing yourself up via command-line interface.

User avatar
rwald
Posts: 153
Joined: Mon Jan 29, 2007 7:14 am UTC
Contact:

Re: 1168: Tar

Postby rwald » Fri Feb 01, 2013 5:26 am UTC

Varriount wrote:Don't forget the 5 or so other archive/zip programs, each with their own unique flag combinations.
Can't there be some sort of standardization?
*Prepares for incoming attacks from Linux Pros*

Here's my script to package up my initramfs into a format that the kernel can use as a pre-boot environment:

Code: Select all

#!/bin/sh
cd /usr/src/initramfs
find . -print0 | cpio -ov -0 --format=newc | gzip -9 > /boot/initramfs.gz

Don't ask me what's going on here. I consider myself lucky every time my laptop boots.

User avatar
phlip
Restorer of Worlds
Posts: 7543
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: 1168: Tar

Postby phlip » Fri Feb 01, 2013 5:30 am UTC

rwald wrote:I immediately thought "tar -xvf my_file_name.tar.gz"; I'm not seeing the challenge, here.

Well, if it's .tar.gz then you want to add a -z there, or you're going to blow us all up.

I know "tar xzvf whatever.tar.gz" and "tar xjvf whatever.tar.bz2", and in emergencies "tar cjvf whatever.tar.bz2 files"... I know there are other flags too, but I really couldn't bring myself to care. Why would I use, say, tar -t when I can just open it up in something like file-roller...

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

drosboro
Posts: 4
Joined: Fri Feb 01, 2013 5:28 am UTC

Re: 1168: Tar

Postby drosboro » Fri Feb 01, 2013 5:31 am UTC

And for bonus points, pipe your tar output across an ssh connection to a remote server, and untar it there - all in one command.

hughperkins
Posts: 16
Joined: Wed Jan 30, 2013 5:47 am UTC

Re: 1168: Tar

Postby hughperkins » Fri Feb 01, 2013 5:35 am UTC

There are only two commands one needs to remember for 98% of usage:

tar -xzf something.tar.gz
tar -xjf something.tar.bz2

It's always x, because 'xtract'
It's always f, because 'file'

then z is 'g(z)ip'
and that leaves 'j' which is not gzip, therefore we know its bz2.

Varriount
Posts: 14
Joined: Sun Aug 12, 2012 8:14 am UTC

Re: 1168: Tar

Postby Varriount » Fri Feb 01, 2013 5:37 am UTC

drosboro wrote:And for bonus points, pipe your tar output across an ssh connection to a remote server, and untar it there - all in one command.

Don't forget all the hacks and loopholes needed for different versions/implementations!

On topic, I wonder how the two people in the comic got into such a situation.

edenist
Posts: 23
Joined: Wed May 16, 2012 5:10 am UTC

Re: 1168: Tar

Postby edenist » Fri Feb 01, 2013 5:45 am UTC

Code: Select all

sudo /etc/init.d bombd stop

NM020110
Posts: 17
Joined: Mon Mar 19, 2012 5:03 am UTC

Re: 1168: Tar

Postby NM020110 » Fri Feb 01, 2013 5:46 am UTC

There's always the easy solution...

tar --help

User avatar
phlip
Restorer of Worlds
Posts: 7543
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: 1168: Tar

Postby phlip » Fri Feb 01, 2013 5:47 am UTC

NM020110 wrote:There's always the easy solution...

tar --help

How certain are you that that's GNU tar running on that bomb?

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: 1168: Tar

Postby EvanED » Fri Feb 01, 2013 5:47 am UTC

phlip wrote:
rwald wrote:I immediately thought "tar -xvf my_file_name.tar.gz"; I'm not seeing the challenge, here.

Well, if it's .tar.gz then you want to add a -z there, or you're going to blow us all up.

I know "tar xzvf whatever.tar.gz" and "tar xjvf whatever.tar.bz2", and in emergencies "tar cjvf whatever.tar.bz2 files"... I know there are other flags too, but I really couldn't bring myself to care. Why would I use, say, tar -t when I can just open it up in something like file-roller...

If you're using GNU tar, the z/j flags are unnecessary; for quite some time, tar has autodetected that situation and added those flags.

Edit: I'm not sure of when this was introduced, but it works as of RHEL 5, where 'tar --version' reports GNU tar 1.15.1. And RHEL5 is fairly ancient... even RHEL6 has been out awhile (and tar there reports 1.23, and my Ubuntu reports 1.26).
Last edited by EvanED on Fri Feb 01, 2013 5:51 am UTC, edited 1 time in total.

Psykar
Posts: 21
Joined: Mon Mar 23, 2009 4:32 am UTC

Re: 1168: Tar

Postby Psykar » Fri Feb 01, 2013 5:49 am UTC

drosboro wrote:And for bonus points, pipe your tar output across an ssh connection to a remote server, and untar it there - all in one command.

I like this one!
One gotcha is f has to be the last arg, as the next arg will be the filename (in this case dash meaning standard input/output)


$ tar cvzf - <somefilenames> | ssh <remote> "tar xvzf - "


Of course this will simply untar in the home directory, it's nicer to actually do the command *from* the remote server

$ cd <where you want stuff>
$ ssh <origin> "tar cvzf - <somefilenames>" | tar xvzf -

Or if you have a version of tar without gzip

$ cd <where you want stuff>
$ ssh <origin> "tar cvf - <somefilenames> | gzip -c" | gunzip -c | tar xvf -


Why do I know this stuff off the top of my head >.<

Varriount
Posts: 14
Joined: Sun Aug 12, 2012 8:14 am UTC

Re: 1168: Tar

Postby Varriount » Fri Feb 01, 2013 5:54 am UTC

Psykar wrote:Why do I know this stuff off the top of my head >.<

I don't know, but could you scrape some of it into my head? Reading 50+ line help printouts gives me a migraine.

I wish a pythonic variant of bash would come out, and act like I expect it to.

lassehp
Posts: 53
Joined: Thu Jun 05, 2008 6:55 pm UTC

Re: 1168: Tar

Postby lassehp » Fri Feb 01, 2013 5:55 am UTC

I guess I would have typed

tar cf - .

to avoid any guessing about existing tar files. It would probably be the shortest possible command, too.
Also, no compression flags, I'm quite posixtive they are not portable.

/Lasse
StratPlayer wrote:Fewer and fewer people writing more and more about less and less. If this trend continues, eventually it will be nobody writing everything about nothing.

User avatar
phlip
Restorer of Worlds
Posts: 7543
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: 1168: Tar

Postby phlip » Fri Feb 01, 2013 5:56 am UTC

Varriount wrote:I wish a psyonic variant of bash would come out, and act like I expect it to.

What I read. I wish that too.

EvanED wrote:If you're using GNU tar, the z/j flags are unnecessary; for quite some time, tar has autodetected that situation and added those flags.

Edit: I'm not sure of when this was introduced, but it works as of RHEL 5, where 'tar --version' reports GNU tar 1.15.1. And RHEL5 is fairly ancient... even RHEL6 has been out awhile (and tar there reports 1.23, and my Ubuntu reports 1.26).

Huh. I didn't know that. Neat.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

Psykar
Posts: 21
Joined: Mon Mar 23, 2009 4:32 am UTC

Re: 1168: Tar

Postby Psykar » Fri Feb 01, 2013 6:00 am UTC

edenist wrote:

Code: Select all

sudo /etc/init.d bombd stop

Code: Select all

sudo systemctl stop bombd.service
sudo systemctl disable bombd.service

Jamaican Castle
Posts: 151
Joined: Fri Nov 30, 2007 9:10 pm UTC

Re: 1168: Tar

Postby Jamaican Castle » Fri Feb 01, 2013 6:03 am UTC

Varriount wrote:Can't there be some sort of standardization?


At a guess, no.

Psykar
Posts: 21
Joined: Mon Mar 23, 2009 4:32 am UTC

Re: 1168: Tar

Postby Psykar » Fri Feb 01, 2013 6:03 am UTC

Varriount wrote:
Psykar wrote:Why do I know this stuff off the top of my head >.<

I don't know, but could you scrape some of it into my head? Reading 50+ line help printouts gives me a migraine.

I wish a pythonic variant of bash would come out, and act like I expect it to.

zsh makes a good go at it! Although I can't get used to it's autocorrection stuff myself.

User avatar
shashwat986
Posts: 60
Joined: Wed Mar 24, 2010 10:15 am UTC

Re: 1168: Tar

Postby shashwat986 » Fri Feb 01, 2013 6:04 am UTC

$ tar --help

simple!

EDIT: Someone posted this before me -.-
Apparently, 1 in 5 people in the world are Chinese. And there are 5 people in my family, so it must be one of them. It's either my mum or my dad. Or my older brother Colin. Or my younger brother Ho-Chan-Chu. But I think it's Colin -- Tim Vine

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: 1168: Tar

Postby EvanED » Fri Feb 01, 2013 6:12 am UTC

I would like to take this opportunity to shamelessly plug a script that I use which I just put on github. (Warning: I don't really do anything like error detection. It also probably won't blow up your computer, but as it helpfully points out, I make no guarantees. Actually I am pretty sure there's one immediate problem: it won't work with filenames with spaces, which is extra galling considering that I consider that a severe failing. :-))

What it does (again, no guarantees) is twofold. First, it lets you type unwhatever file.blah at it and it will unpack file.blah as appropriate. You can see the kinds of archives it knows about near the top -- right now, it's .tar, .tar.gz/.tgz, .tar.bz2, .gz, .bz2, .zip, and .lzma. (...I thought I added .xz, but I guess not.) But more helpfully, what it does is first get a listing of all of the files inside the archive. If there is only one file in it or if everything unzips to a single directory, it just unpacks it; if it would unzip to multiple things and throw up all over your current directory, then it will make a directory for you and put the contents in there instead.

(I apparently use the z/j flags anyway. :-))

Psykar wrote:zsh makes a good go at it! Although I can't get used to it's autocorrection stuff myself.

zsh is what you get if you try to polish a turd with another turd. It's a bit shinier than it was before, but... well, you know the rest.

<-- uses zsh
Last edited by EvanED on Fri Feb 01, 2013 6:38 am UTC, edited 1 time in total.

User avatar
Primis
Posts: 61
Joined: Fri Jul 15, 2011 5:07 am UTC
Location: New York
Contact:

Re: 1168: Tar

Postby Primis » Fri Feb 01, 2013 6:19 am UTC

lassehp wrote:I'm quite posixtive they are not portable.

That made my day()
Image
Key Fingerprint: 49A8 7E39 87C1 DFB2 B0EB F7F4 1235 F2BB 9442 E47F
PhoenixRising wrote:What is this sleep you speak of? There is only the castle. All must yield to the castle.

vector010
Posts: 17
Joined: Thu Jan 27, 2011 9:17 pm UTC

Re: 1168: Tar

Postby vector010 » Fri Feb 01, 2013 6:21 am UTC

Yeah, my usage of *nix is so minimal right now I'd be dead unless "man tar" counted. :P

The title text does bring up a good point though. I mean, on the PC side we're still mucking around with ZIP and RAR which came out in 1989 and 1993 respectively. That's 20+ year old compression technology we are using. :P

User avatar
alvinhochun
Posts: 54
Joined: Wed Nov 14, 2012 3:07 pm UTC

Re: 1168: Tar

Postby alvinhochun » Fri Feb 01, 2013 6:24 am UTC

Interesting that is is running as root, unless that is a fake shell.

I bet I'll type:

Code: Select all

~# halt


If seriously:

Code: Select all

~# tar --version

and hope it doesn't explode.

BTW does a wrong file path count as valid? (though this is not an important point in the comic.)

User avatar
Primis
Posts: 61
Joined: Fri Jul 15, 2011 5:07 am UTC
Location: New York
Contact:

Re: 1168: Tar

Postby Primis » Fri Feb 01, 2013 6:27 am UTC

Image
Key Fingerprint: 49A8 7E39 87C1 DFB2 B0EB F7F4 1235 F2BB 9442 E47F
PhoenixRising wrote:What is this sleep you speak of? There is only the castle. All must yield to the castle.

User avatar
Max™
Posts: 1792
Joined: Thu Jun 21, 2012 4:21 am UTC
Location: mu

Re: 1168: Tar

Postby Max™ » Fri Feb 01, 2013 6:36 am UTC

>.>

Does it count if I don't have to google to get to one of the many askbuntu/command line fu/help sites because I can just type ask and it'll come up from my history?

What if you're using chrome?

I have some commands memorized, but when it comes to tarballs they either auto-extract or I like the good old ctrl-c ctrl-v shuffle so I don't fuck it up.


Though I'll note that tar --help would probably be my first try if I had no other choices. :D
Last edited by Max™ on Fri Feb 01, 2013 6:37 am UTC, edited 1 time in total.
mu

Varriount
Posts: 14
Joined: Sun Aug 12, 2012 8:14 am UTC

Re: 1168: Tar

Postby Varriount » Fri Feb 01, 2013 6:36 am UTC

vector010 wrote:Yeah, my usage of *nix is so minimal right now I'd be dead unless "man tar" counted. :P

The title text does bring up a good point though. I mean, on the PC side we're still mucking around with ZIP and RAR which came out in 1989 and 1993 respectively. That's 20+ year old compression technology we are using. :P

Isn't tar and the like just as old, if not older?
What's interesting is that we're starting to see amalgamations of various file formats. The other day I discovered that the SMART Notebook file extension used by a program from my school is actually a zipped up archive of html files.

EvanED, Great script, I'll download it as soon as I'm on my computer, and not a phone.

fenix849
Posts: 10
Joined: Wed Oct 01, 2008 3:42 am UTC
Location: Melbourne, Australia

Re: 1168: Tar

Postby fenix849 » Fri Feb 01, 2013 6:41 am UTC

Out of note i was wondering given the 10 seconds allow for a valid response.

What the shortest valid tar command is:

(Sticking to file name standards etc).

This is my attempt:

Code: Select all

tar cf a.tar .

Meem1029
Posts: 379
Joined: Wed Jul 21, 2010 1:11 am UTC

Re: 1168: Tar

Postby Meem1029 » Fri Feb 01, 2013 6:45 am UTC

Hmm, so sticking to file name standards would mean that we can't just call it a. I'll submit

Code: Select all

tar xf b.tar

as slightly shorter than yours. It does make the assumption that such a file exists though, but I would consider that a safe assumption to make.
cjmcjmcjmcjm wrote:If it can't be done in an 80x24 terminal, it's not worth doing

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: 1168: Tar

Postby EvanED » Fri Feb 01, 2013 6:46 am UTC

Varriount wrote:Isn't tar and the like just as old, if not older?
What's interesting is that we're starting to see amalgamations of various file formats. The other day I discovered that the SMART Notebook file extension used by a program from my school is actually a zipped up archive of html files.

tar is pretty ancient (it stands for "tape archive" for crying out loud, as if that consists of even 1/10% of tar's use nowadays). It doesn't even do compression at all -- that's why you see the .tar.gz/.tar.bz2/.tar.xz/etc. files. The actual compression formats there can only compress one file into one file (as opposed to zip, which can put many files into one file and is able to extract a single file without opening the whole archive -- a great feature in the days of floppies but much less relevant now), so you first use tar to combine several files into one then use some compression thing to actually make it smaller.

And the "zip file as file format" is actually pretty common. I think OOXML is a zip file of XML files, and I know JAR is a zip file of a bunch of .class files (and other stuff). Maybe .xpi Firefox/Thunderbird extensions too...

EvanED, Great script, I'll download it as soon as I'm on my computer, and not a phone.

Thanks. Though I was kidding around with the blowing up your computer thing, it really isn't made to be bullet-proof, so don't use it on your only copy of something important. If you see something that's wrong, let me know.

Alphonse
Posts: 7
Joined: Fri Feb 01, 2013 5:59 am UTC

Re: 1168: Tar

Postby Alphonse » Fri Feb 01, 2013 6:47 am UTC

I think that, in the topic title, the T should not be capitalised, since the comic name is "tar", not "Tar". Or has it been defined in the XKCD Forums Style Guide that topic titles should always capitalise the first word? In that case, does Randall's creative choice of naming the comic "tar" trump over the Style Guide?

KooKiz
Posts: 1
Joined: Fri Feb 01, 2013 6:46 am UTC

Re: 1168: Tar

Postby KooKiz » Fri Feb 01, 2013 6:48 am UTC

And that's why you should have called yourself xvzf rather than xkcd. Poor nickname choices lead to impromptu nuclear hazard!

Varriount
Posts: 14
Joined: Sun Aug 12, 2012 8:14 am UTC

Re: 1168: Tar

Postby Varriount » Fri Feb 01, 2013 6:51 am UTC

EvanED wrote: it really isn't made to be bullet-proof, so don't use it on your only copy of something important. If you see something that's wrong, let me know.

That's the beauty of github and other online repositories - open improvement!

villadelfia
Posts: 98
Joined: Sat Apr 28, 2007 2:35 am UTC

Re: 1168: Tar

Postby villadelfia » Fri Feb 01, 2013 7:14 am UTC

phlip wrote:
rwald wrote:I immediately thought "tar -xvf my_file_name.tar.gz"; I'm not seeing the challenge, here.

Well, if it's .tar.gz then you want to add a -z there, or you're going to blow us all up.

I know "tar xzvf whatever.tar.gz" and "tar xjvf whatever.tar.bz2", and in emergencies "tar cjvf whatever.tar.bz2 files"... I know there are other flags too, but I really couldn't bring myself to care. Why would I use, say, tar -t when I can just open it up in something like file-roller...


On tar versions from the last 5 years, you can tar xf file.tar.gz/bz2/xz and it will Do The Right Thing™. This goes for both GNU tar and BSD tar.

Creating still requires tar c[zjZ]f outfile <infiles...> to select which format though.

Note: When in doubt, skip the v. It moves the bottleneck from the cpu/hard disk to the speed of your terminal. Try unpacking something huge, like say the Qt Library source code with and without v and time it.

I usually only use v if I think something is going wrong.


By the way, the shortest valid tar command is:

Code: Select all

tar x

Which reads a tarball from standard input. And unpacks is to the current working directory.
Last edited by villadelfia on Fri Feb 01, 2013 7:26 am UTC, edited 2 times in total.

User avatar
RAGBRAIvet
Posts: 116
Joined: Tue Apr 05, 2011 12:50 pm UTC
Location: 43° 53' 03" -91° 14' 06"

Re: 1168: Tar

Postby RAGBRAIvet » Fri Feb 01, 2013 7:17 am UTC

Excuse me.  But one has ten seconds to enter a valid command.  If one does not enter **anything**, said timer remains at 10 seconds, right?

Sometimes the only winning move is to not play.

DaphneDiane
Posts: 4
Joined: Fri Feb 01, 2013 7:13 am UTC

Re: 1168: Tar

Postby DaphneDiane » Fri Feb 01, 2013 7:23 am UTC

What about?

Code: Select all

tar tf /dev/null

It's a valid command - works on almost any unix system regardless of what files exists.


Return to “Individual XKCD Comic Threads”

Who is online

Users browsing this forum: Google [Bot] and 45 guests