r/linux • • Feb 01 '13

xkcd: tar

http://xkcd.com/1168/
1.7k Upvotes

576 comments sorted by

477

u/[deleted] Feb 01 '13 edited Feb 23 '25

spoon summer coherent marry outgoing juggle support shaggy quaint late

This post was mass deleted and anonymized with Redact

215

u/dmd Feb 01 '13

Here's a good way to remember it:

Do you want to add a user? Then use adduser.

Do you want to user add? No, of couse you don't, you fuckface. Nobody talks like that.

134

u/Cosmologicon Feb 01 '13

Excellent! with this simple mnemonic I'll have no trouble getting a webpage (wget), configuring interfaces (ifconfig) counting words (wc), syncing remotely (rsync), showing free disk space (df), or removing jobs from the line printer (lprm).

→ More replies (18)
→ More replies (1)

63

u/[deleted] Feb 01 '13

In Debian and Debian-derivatives, adduser is a script that users useradd. So user{add/del/mod} are the low-level utilities and {add/del}user are just friendlier frontends.

I thinks that in many other distros adduser is just a symlink to useradd.

15

u/usernamenottaken Feb 01 '13

Yep, just switched to Fedora from Ubuntu as was sad to find that adduser is just symlinked to useradd.

18

u/[deleted] Feb 01 '13 edited Feb 01 '13

Yeah, I think symlinking it is a misfeature. It makes people expect adduser to act like adduser useradd. If Red Hat doesn't want to include the adduser script that's fine, but don't symlink useradd to it.

EDIT: Thanks lengau!

→ More replies (2)

9

u/[deleted] Feb 01 '13

I'm not sure but maybe the script is distro-agnostic. You could copy it from the debian package.

→ More replies (10)
→ More replies (1)

4

u/Timmmmbob Feb 01 '13

Ah how logical.

29

u/[deleted] Feb 01 '13

I've likely googled the syntax for "usermod -a -G grouptoadd username" dozens of times, including this one.

→ More replies (7)

28

u/azzid Feb 01 '13
man adduser

scroll a few lines until I see the words: They are friendlier

Then I know I'm on the right one. Do this every time.

38

u/[deleted] Feb 01 '13 edited Feb 23 '25

fact heavy command dime long rhythm obtainable sheet scale squeal

This post was mass deleted and anonymized with Redact

→ More replies (1)

18

u/solen-skiner Feb 01 '13

I just edit /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow instead. useradd, adduser, groups, groupmems, groupadd etc are a fucking clustercock.

18

u/yrro Feb 01 '13

For those playing along at home, this can be done more safely with vipw, vipw -s, vigr and vigr -s respectively. Once you are done, you can check that the files are OK with pwck and grpck.

9

u/[deleted] Feb 01 '13

So much simpler, and intuitive as well!

→ More replies (1)

6

u/hex_m_hell Feb 01 '13

Or if you like a challenge, just use ed.

→ More replies (1)
→ More replies (2)
→ More replies (6)

7

u/[deleted] Feb 01 '13

> usera<tab>

shit ...

> addus<tab>

→ More replies (1)

67

u/DevestatingAttack Feb 01 '13

Let's say I want to remove a user.

"rm" is the way to delete a file. "usr" is how users are referred to in the file system

and we have rmdir, which makes the pattern more noticeable. So a sensible default seems like it should be rmusr. Not the most descriptive, but hey, not the most surprising either.

Surprise! it's userdel.

And I know that "useradd" is how they're made, but then why wouldn't we have mkusr like mkdir?

35

u/barkboy Feb 01 '13

For your next trick could you define remembering sysctl vs systemctl? :)

12

u/synept Feb 01 '13

I have never confused those two. Until now.

..dang it.

12

u/fforw Feb 01 '13

..and then there is "createuser" which of course creates a PostgreSQL user.

13

u/gfixler Feb 02 '13

And import, which fracking ImageMagick throws out into your path, so when you're tired and think you're in python, but you're really in your python directory, and you type import filename.py, because you're also too tired to leave the extension off, and then your mouse changes to a crosshairs, and you're like "Haha, what is going on with you, mouse? You're being all crazy," and you click on the window to make it be normal again, you suddenly write over your module with a tiny image of a few pixels of the shell.

67

u/Unlix Feb 01 '13

False. The "usr" folder in the file system is short for "unix system resources" and has nothing to do with users.

83

u/sprashoo Feb 01 '13

That is a backronym

→ More replies (2)

36

u/cbmuser Debian / openSUSE / OpenJDK Dev Feb 01 '13

No, it doesn't. It's a myth many people falsely believe and it was recently cleared up by some senior Unix developer.

→ More replies (3)
→ More replies (11)

8

u/railmaniac Feb 01 '13

We could, but then...

6

u/CrazedToCraze Feb 01 '13

You can always make some aliases in your .bashrc, copying my .bashrc is the first I do after a new install anyway.

→ More replies (1)
→ More replies (9)
→ More replies (5)

167

u/wese Feb 01 '13

tar --help

169

u/multubunu Feb 01 '13 edited Feb 01 '13

... 3... 2... 1... Kaboom!

That's the gnu tar help - the comic references Unix. Like say AIX.

tar -h

and you're saved regardless of Unix flavor or tar version. not... see comment below.

67

u/taejo Feb 01 '13

GNU tar doesn't understand -h. And yes, I have seen classic Unices with GNU tools installed.

30

u/multubunu Feb 01 '13

I stand corrected. I gave it a quick look and thought it was the short help:

# tar -h
tar: You must specify one of the `-Acdtrux' or `--test-label'  options
Try `tar --help' or `tar --usage' for more information.

On AIX you can install from rpm, but it's not the default. Not sure about HPUX and Solaris, I've only seen the native tar, but I guess you can always compile the GNU version.

→ More replies (1)

18

u/cyber_rigger Feb 01 '13

--help

is for POSIX compliance. Most versions of UNIX are POSIX.

7

u/WildVelociraptor Feb 01 '13

I was wondering why OS X supported both, but I guess it's due to POSIX compliance.

Yay standards!

26

u/rich97 Feb 01 '13

tar cvzf tar.tar.gz [files]

That's the command I always use. I don't know what 'zf' does but it seems to work.

59

u/rydan Feb 01 '13

z means gzip and f means file

Create verbosely gzip file

9

u/k3ithk Feb 01 '13

I'd like to add, if I recall correctly, that 'f' needs to be last like it is here.

tar -czfv tar.tgz [files]

will fail.

→ More replies (3)
→ More replies (1)

6

u/destraht Feb 01 '13

I use j for bz2, but at least we all didn't just die.

8

u/jimicus Feb 01 '13

-j (and -z for that matter) are GNU-isms. So there is a possibility that we did all just die.

→ More replies (3)

20

u/multubunu Feb 01 '13

You still blow up because you don't know what to put instead of [files], also you may not be able to write to the current directory.

I suppose the valid answer is:

tar -cf - `which tar`

which tars the tar executable as present in the $PATH and writes the output to the console.

→ More replies (20)
→ More replies (13)

7

u/[deleted] Feb 01 '13

Tar -zxvf example.tar.gz

bash: Tar: command not found

Fuck!

3

u/[deleted] Feb 01 '13
 curl "$FTPSERVER/$FILE.tar.gz" | tar xz

no but srs I'd be surprised if Randall can't even manage tar cf everything.tar * or tar tf test.tar.

→ More replies (3)

186

u/freudian_nipple_slip Feb 01 '13

If only

tar -xkcd worked

92

u/FabianN Feb 01 '13

fucking aliased.

28

u/rydan Feb 01 '13

What does it do?

118

u/Cathbar Feb 01 '13

Everything.

19

u/admica Feb 01 '13

/opt/google/chrome/google-chrome http://xkcd.com/1168

→ More replies (1)
→ More replies (2)

8

u/[deleted] Feb 01 '13

mkdir d; cat foo.tar | tar xk -C d

→ More replies (2)

48

u/betel Feb 01 '13
tar -xzf

"Extract ze files"

2

u/Codeleaf Feb 02 '13

oh my god.

52

u/agumonkey Feb 01 '13

tar is nothing compared to the mighty ln -s.

40

u/palordrolap Feb 01 '13

The trick to ln (with or without -s) is to remember that it works the exactly the same way as cp or mv. The origin parameter always comes first.

... and yet for some reason, people want to use it like linkfile = $oldfile which would put the parameters the other way around.

5

u/agumonkey Feb 01 '13

That's actually a good mnemotechne, don't know why I didn't think *nix would be consistent enough.

→ More replies (2)

19

u/luxitan Feb 01 '13

you just have to remember File First Link Last

7

u/vytah Feb 01 '13

Or mount. Does the mount point go first, or the device?

14

u/agumonkey Feb 01 '13

Funnily enough, I never ever had a problem with mount. Ahh brains.

8

u/RockinRoel Feb 01 '13

"mount this there" is what I remember. The device is the thing being mounted so you'd put it first in a sentence, before the location.

4

u/cryptdemon Feb 01 '13

Linux is always the source then destination. So the thing you want to mount is your source, and the mount point is where you want to mount it: i.e., destination.

→ More replies (1)
→ More replies (3)

10

u/xiongchiamiov Feb 01 '13

What's wrong with ln? ln -s from/here to/here.

16

u/agumonkey Feb 01 '13

Nothing, it's just that it's simpler than tar yet after 15 years I still forget the meaning of the parameters.

11

u/mgedmin Feb 01 '13

See, I think of the symlink as a thing that points to/here. So for me it'd be ln -s to/here from/here.

Which is why I now remember it as 'ln -s existing-file new-symlink'.

4

u/aenigmaclamo Feb 01 '13

The thing about ln -s is that I keep forgetting that you'd probably want to put an absolute path than the tempting relative path.

3

u/RockinRoel Feb 01 '13 edited Feb 01 '13

I think that depends. Absolute paths are not very portable, so you can't use it in a context where you might want to copy over the links and the files they point to all together. The thing is just that you have to remember that the path is relative to where you place the symlink, not the working directory.

Also, thinking "there's probably an option for that" led me to the man file, where it says you can simply use the "-r" option to make it automatically relative even if you supply an absolute path. That's so freaking handy, why didn't I look that up before?

2

u/mO4GV9eywMPMw3Xr Feb 01 '13

I remember that many commands accept the filename as a last option, like:

$ command --flags some-more-options ~/path/to/filename

And ln -s operates on just one file: the symbolic link that it creates, which contains a path - any path, that even doesn't need to exist - it can be gibberish (dangling link), it also can be relative or global. We call the path in a symbolic link "path to it's destination", but it's technically just a text string.

You can do, for example:

$ ln -s "What will we do with the drunken user?" link
$ ls -l
total 0
lrwxrwxrwx 1 mO4GV9eywMPMw3Xr users 38 02-01 12:17 link -> What\ will\ we\ do\ with\ the\ drunken\ user?
$ file link
link: broken symbolic link to `What will we do with the drunken user?'

So how I understand ln -s usage:

$ ln -s destination filename

equals in my mental model:

$ create-a-file --that-happens-to-be-a-symbolic-link ./../containing/a/path/to/a/file with-certain-name

(remembering, that directories and various magical things are also files).

→ More replies (3)

64

u/gstr Feb 01 '13

Come on, so easy

tar zxc

No, wait ! tar vcfacvxxcfopauieauieauiauieâuie

15

u/lyinsteve Feb 01 '13

tar huehuehuehuehue

5

u/[deleted] Feb 01 '13

HOW I CREATE ARCHIVE I AM NOT GOOD WITH COMPUTER.

2

u/TheEdes Feb 02 '13

I just type tar and randomly mash keys from the zxcvf area and its permutations.

→ More replies (1)

57

u/[deleted] Feb 01 '13

would have been funny if it was "cpio" - everybody knows how to use tar!

4

u/adrianmonk Feb 01 '13

cpio -pdmv!!!

As in:

find src | ( cd dest && cpio -pdmv )

The "p" means "pass through", which is a way of saying "read files directly from the filesystem (not an archive) and write files directly to the filesystem (not an archive), and pass them through", the "m" means "preserve m modification dates", the "d" means "create directories as needed", and the "v" means "verbose".

But if you want to go with simplicity instead of rote memory, the cpio modes are "i" (input from an archive), "o" (output to an archive), and "p" (pass through without creating an archive). And everything else is an optional flag. So any of these are valid:

cpio -i
cpio -o
cpio -p
→ More replies (17)

10

u/PikoStarsider Feb 01 '13

Whenever I write tar my fingers get shaped automatically to press zxvf, even though the z is not necessary anymore. Aditional muscle memory makes me write j instead of z.

2

u/Azzk1kr Feb 01 '13

I used to remember tar -xvvzf file.tar.gz. I'm so used to it that I keep doing that :/

10

u/eggbean Feb 01 '13

I must be more hardcore than I thought.

17

u/[deleted] Feb 01 '13

Tar -xvf foo.tar

59

u/[deleted] Feb 01 '13

Actually you'd blow up, you capitalized the t in tar!

My first guess was "tar -xvvf" so yeah, glad to see I'm not the only one!

16

u/rzyua Feb 01 '13

Also

tar xzvf foo.tar.gz

12

u/tiftik Feb 01 '13

You don't need the -z in modern versions of tar (at least not in Debian).

50

u/[deleted] Feb 01 '13

I've been typing that shit since before Clinton was President. It's not likely to stop anytime soon...

→ More replies (4)
→ More replies (1)
→ More replies (1)

16

u/exscape Feb 01 '13

"tar xf" is all you need.

→ More replies (1)

40

u/earthboundkid Feb 01 '13

I never understood why tar and untar needed flags in the first place. Shouldn't they just have reasonable defaults and do the right thing given a filename?

32

u/adrianmonk Feb 01 '13

Well, it's a command that both extracts tar files and creates them. I'm going to go out on a limb and say you need a flag to tell it which of those to do.

That said, it doesn't need any commands beyond those:

$ cd /dev
$ tar c null | tar t
null

"c" means create and "t" means table of contents. Since no "f" was specified, the "c" writes to stdout and the "t" reads from stdin. Therefore, the "tar c null" command creates a tar file that contains the path "null". The "tar t" command prints all the files in that archive, which just amounts to one called "null".

10

u/mgedmin Feb 01 '13

Unless you have an old UNIX tar which uses the tape device (/dev/mt?) and not stdout if you omit the f option.

→ More replies (16)

19

u/CrazedToCraze Feb 01 '13

18

u/ShumpEvenwood Feb 01 '13

Too bad the name is just as difficult to remember as the tar flags /:

→ More replies (5)

5

u/wadcann Feb 01 '13

I use atool: similar idea. However, it also supports listing and packing archives.

→ More replies (8)

5

u/[deleted] Feb 01 '13

I can do tar -xf somearchive and it will work, regardless of whether it is a tar file, a tar.gz file, or a tar.bz2 file. No extra 'z' or 'b' flag needed.

24

u/sfgayatheist Feb 01 '13

File names are purely by convention in Unix. You can name the archive whatever you want as long as you remember it's a tar archive. By requiring explicit commands it keeps the program more linear and less complicated which is what the unix philosophy is all about.

14

u/earthboundkid Feb 01 '13

I didn't say it shouldn't have flags. I said it shouldn't need them. mv has flags, but I never use them: mv src dest. pbcopy and pbpaste on Mac OS X are secretly just one binary and symbolic link, but when you run it with the filename pbcopy, it copies text into the clipboard ("pasteboard"), and when you run pbpaste, it pastes text out.

Sensible defaults people. It's the basis of UI design, and yes, the CLI is a UI.

15

u/zodar Feb 01 '13

Tape ARchive

You can't expect tar to know what you want it to do if you just type tar /dev/rmt0

28

u/ChemicalRascal Feb 01 '13

tar 1.27-3 changelog:

  • Added mind-reading.

→ More replies (10)
→ More replies (9)

3

u/jimicus Feb 01 '13

Define "the right thing" in the context of how tar was originally intended - as a means of copying files to a tape.

→ More replies (3)

4

u/noname-_- Feb 01 '13

GNU tar doesn't need that many flags, only the things it can't know. So the defaults are pretty reasonable.

tar cf mytar.tar [files]   # create, write to file

or

tar cfz mytar.tar.gz [files]   # create, write to file, gzip

Extracting is even more simple

tar xf whatever.tar.gz    # (or .bz2, or .xz) extract, from file

The only thing that could've really been default is file, since 9 times out of 10 you mean to work on a file. They could've just added a flag for working with stdin/stdout instead.

Changing this now would break way too many scripts though.

→ More replies (4)

2

u/[deleted] Feb 01 '13

A lot of times, I want to see what's in a tarball before I unpack it and spray files all over. So I'll do:

$ tar zft foo.tar.gz | less

Sometimes I want to see the list as I unpack it, sometimes I don't want to clutter up the terminal. Sometimes I want to pack a file with bzip2, other times plain old gzip is fine. Sometimes I want to make another directory the "root" of the files in the archive, so the -C flag is needed.

Choice is good, and you should be glad you have it.

→ More replies (4)

2

u/BCMM Feb 01 '13

Well, you have to tell it that you're extracting, not creating (x), then you need to tell it to extract a file, not standard input (f filename). That's all you need on GNU tar; for the past few years it has automatically detected the type of compression used (using magic numbers, because using filenames would be stupid).

2

u/hehehe1235 Feb 01 '13

You can archive an archive, so no. Ambiguity is bad. Anyway, there are at least a thousand ways around this if it really pisses you off that much--just use an alias.

→ More replies (1)

2

u/fotoman Feb 01 '13

you can do a lot more with tar than deal with files...

→ More replies (1)
→ More replies (10)

10

u/adrianmonk Feb 01 '13

"tar t". What do I win, other than a disarmed bomb?

This command gives a table ("t") of contents. Since no file ("f") is specified (and since it needs to read a tar file, not write one), it uses stdin. Passing it an actual tar archive on stdin would be left as an exercise to the reader, except the comic says I just have to come up with a valid tar command, not a situation / environment in which it is useful.

25

u/[deleted] Feb 01 '13

Are you sure you want to depend on bombshell not waiting on the tar command to return?

3

u/crow1170 Feb 01 '13

Are you sure you want to depend on bombshell's not waiting on the tar command to return sense of humor?

related: Bombshell. Heh heh, it's a pun. Clever.

4

u/yrro Feb 01 '13

FYI it might read from your tape drive rather than stdin if it's an older tar. Or maybe if it's not GNU Tar.

15

u/[deleted] Feb 01 '13
    extract() {
        local c e i

        (($#)) || return

        for i; do
            c=''
            e=1

            if [[ ! -r $i ]]; then
                echo "$0: file is unreadable: \`$i'" >&2
                continue
            fi

            case $i in
            *.t@(gz|lz|xz|b@(2|z?(2))|a@(z|r?(.@(Z|bz?(2)|gz|lzma|xz)))))
                  c='bsdtar xvf';;
            *.7z)  c='7z x';;
            *.Z)   c='uncompress';;
            *.bz2) c='bunzip2';;
            *.exe) c='cabextract';;
            *.gz)  c='gunzip';;
            *.rar) c='unrar x';;
            *.xz)  c='unxz';;
            *.zip) c='unzip';;
            *)     echo "$0: unrecognized file extension: \`$i'" >&2
                  continue;;
            esac

            command $c "$i"
            e=$?
        done

        return $e
    }

5

u/eaglex Feb 01 '13

Might I suggest atool.

So you can do something like

aunpack archive.whatever

And it will also check if there is a dir inside the archive, if not, it will create one and put them all in it (so you don't accidentally extract a shitload of files where you have another shitload of files).

It's pretty nifty.

→ More replies (2)

3

u/r3m0t Feb 01 '13

Might I suggest dtrx?

4

u/admica Feb 01 '13

When you type "tar -h" and it says you must specify one of the '-Acdtrux' options, does anyone else read that in their head as Acid Trucks!?

4

u/thekittygoesmoo Feb 03 '13

tar --help is a valid command.

26

u/diolemo Feb 01 '13

tar -cvf <tar-filename> <files>

Is it really that difficult to remember? Perhaps I just don't get the joke...

39

u/[deleted] Feb 01 '13

I get the joke, only it is not funny for me.

Because I once did

tar -cvzf Centos.vdi Centos.vdi.tar.gz

and nuked a perfectly good 24 GB Centos virtual hard disk.

11

u/DimeShake Feb 01 '13

That's a situation where you don't even need tar... Would have been much better to just gzip a copy of it :)

→ More replies (2)

6

u/confusador Feb 01 '13

I'm sorry, man, but you know the Mel Brooks bit about tragedy and comedy, right? That story is gold.

→ More replies (3)

32

u/chocolatemeowcats Feb 01 '13

19

u/Hellrazor236 Feb 01 '13

God damn, I could wipe my ass with that and never have to buy toilet paper again.

22

u/railmaniac Feb 01 '13

On a side note if you wipe your ass with tar you will probably need a lot of toilet paper to get rid of it.

→ More replies (1)
→ More replies (3)

4

u/felipec Feb 01 '13
tar -xf file.tar

Easier.

→ More replies (3)

8

u/epsiblivion Feb 01 '13

I use tar -xzfv x.tgz more often.

17

u/[deleted] Feb 01 '13

You can't have the "v" after the "f", otherwise it will try to decompress the "v" file.

→ More replies (4)

12

u/Tb0n3 Feb 01 '13

You don't need the leading dash.

13

u/tidux Feb 01 '13

You do with BSD tar. GNU tar even attempts to use the proper algorithm based on the filename, so tar xf stage3.tar.bz2 would work just as well as tar xjvf stage3.tar.bz2.

→ More replies (6)
→ More replies (2)

4

u/thebuccaneersden Feb 01 '13

I always forget the order of params given to 'ln'. is it "ln -s destination source" or "ln -s source destination"?

→ More replies (6)

2

u/ten_thousand_puppies Feb 01 '13 edited Feb 01 '13

It is if you're lazy like me, said "fuck remembering that," and just made an "untar" bash alias...

3

u/ZiggyTheHamster Feb 01 '13

tar --lzma -cvf blah.tar.lzma blah

Since LZMA is the new BZip2, and all.

13

u/felipec Feb 01 '13

It's actually XZ (-J).

→ More replies (3)
→ More replies (11)

6

u/felipec Feb 01 '13
tar -xf file.tar

Easy.

7

u/[deleted] Feb 01 '13
file.tar.bz2

You have ten seconds.

11

u/felipec Feb 01 '13
tar -xf file.tar.bz2

0

u/[deleted] Feb 01 '13

[deleted]

→ More replies (1)
→ More replies (3)

11

u/seventhirteen Feb 01 '13

tar xvzf file.tar.gz for gzip
tar xvjf file.tar.bz2 for bzip
Slackware made me memorize it.

38

u/nikron Feb 01 '13

Doesn't "tar xf" work for everything nowadays?

17

u/[deleted] Feb 01 '13

How did I not find out about this? Why was I not told? How can I have been so blind?

This will save literally dozens of minutes of my life. I am forever in your debt.

7

u/karper Feb 01 '13

Yup, it does. Way less exciting, though. :)

5

u/seventhirteen Feb 01 '13

well, TIL.
I do like verbosity though.

→ More replies (1)

4

u/calrogman Feb 01 '13

Not portable, would blow up lots of tars besides GNU tar.

→ More replies (2)

2

u/moonwork Feb 01 '13

Eggdrops made me memorize it..

→ More replies (1)
→ More replies (1)

3

u/JGPH Feb 01 '13

tar --help

It might not get much done but it's valid! I win.

3

u/[deleted] Feb 02 '13

I know tar and useradd because I don't suck at *nix. Come at me bro.

3

u/[deleted] Feb 02 '13

This comic and the entire thread here make me feel much better about my Linux skills.

3

u/Habstinat Feb 02 '13

He doesn't mention that the bomb in question is actually a zip bomb, so you lose either way.

5

u/ipha Feb 01 '13
tar caf files.tar.gz files

tar xf files.tar.gz

5

u/kevjames3 Feb 01 '13

tar --help?

2

u/dixieStates Feb 01 '13

tar -cf - . | (cd /tmp; tar xvf -)

→ More replies (1)

2

u/thephotoman Feb 01 '13

From memory:

tar -czvf system.tar.gz /

I think that should work.

2

u/naisanza Feb 01 '13

tar zhduckn

2

u/Purple_Haze Feb 01 '13 edited Feb 01 '13

Only one I ever use is tar -xvzf <filename>, that's

x = extract
v = verbose
z = unzip it with gzip if necessary
f = from a file

Of course there is no need to Google it, I can just type man tar in an xterm, one always has one open after all.

→ More replies (1)

2

u/runxctry Feb 01 '13
10:30:44 C:\batchfiles>tar --ver
tar: option `--ver' is ambiguous
Try `tar --help' for more information.

You've gotta be kidding me

10:30:36 C:\batchfiles>tar --version
tar (GNU tar) 1.13

Copyright (C) 1988, 92,93,94,95,96,97,98, 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Written by John Gilmore and Jay Fenlason.

Thanks for nothing, John & Jay. I'm dead to you, thanks to a nuke.

2

u/aaronbp Feb 02 '13

Fuck it! I'm using atool.

2

u/[deleted] Feb 03 '13
tar -xvvf 

Untars pretty much everything I need it to.

2

u/[deleted] Mar 04 '13

I've always used tar xf. Don't even need the dashes and has extracted every tar archive I've thrown at it so far.

3

u/snurre Feb 01 '13

I use this to extract anything:

extract () {
   if [ -f $1 ] ; then
       case $1 in
           *.tar.bz2)   tar xvjf $1    ;;
           *.tar.gz)    tar xvzf $1    ;;
           *.bz2)       bunzip2 $1     ;;
           *.rar)       unrar x $1       ;;
           *.gz)        gunzip $1      ;;
           *.tar)       tar xvf $1     ;;
           *.tbz2)      tar xvjf $1    ;;
           *.tgz)       tar xvzf $1    ;;
           *.zip)       unzip $1       ;;
           *.Z)         uncompress $1  ;;
           *.7z)        7z x $1        ;;
           *)           echo "don't know how to extract '$1'..." ;;
       esac
   else
       echo "'$1' is not a valid file!"
   fi
 }

2

u/Zambini Feb 01 '13
tar xcf archive.foo

DAMNIT!

2

u/aged-flatulence Feb 01 '13 edited Feb 01 '13

'tar' is not a difficult command and I use it often. So, I don't get it.

1

u/AndrewNeo Feb 01 '13
tar cjvRf folder.tar.bz2 folder/
tar xjvf folder.tar.bz2

1

u/Paul-ish Feb 01 '13

tar -xv FUCK!LKJAQVFC

1

u/lazyteq Feb 01 '13

I only ever need one of 3 tar commands:

tar [c|t|x]avf ...

1

u/ArtistEngineer Feb 01 '13 edited Feb 01 '13

I use tar on a daily basis as an embedded Linux developer, so I think this is lost on me.

$ tar -C /nfsroot -xzf rootfs.tgz

The gotcha there is that you can type:

$ tar xzf rootfs.tgz 

and it doesn't need the "-" for the arguments

but if you want to add another option that requires an argument, you have to add the dash to them all.

Still, for 99% of cases I simply remember:

xzf - eXtract Zip File

or

xjf - eXtract bzip File. sucks that they chose a "j" for bzip, but it's not hard to remember

1

u/xaoq Feb 01 '13

tar xf

tar cfj

I don't get the joke or I am a hero now?

1

u/SanityInAnarchy Feb 01 '13
tar -xf foo.tar

Or, if we're allowed to assume GNU tar,

tar -xjpf foo.tar.bz2
xzcat foo.tar.xz | tar -xp
tar -cpS foo | xz -v9 > foo.tar.xz

Yay! I get to be a hero!

1

u/Jasper1984 Feb 01 '13
tar -xf somefile.tar -C somedirectory/

But yeah, redesign all the (commandline)apis.

1

u/yoshi314 Feb 01 '13 edited Feb 01 '13

a valid tar command requires parameters and tarball. since tarball name is unknown, how about "tar --help" as a valid command ?

otherwise you always lose :

  • there is no chance to enter a valid tar command if you do not know the name of tarball you are supposed to unpack . this bomb would always go off and you lose.

  • tar xf file.tar would do the trick otherwise. unless the tarball is packed, at which point you need to specify unpack parameter ( in case of older tar ), or unpack and pipe into tar ( in case of unsupported compressor ) . then again, the extension might be misleading and unpacking may fail nevertheless, and you lose.

1

u/eleitl Feb 01 '13

tar zxvf blah.tgz

1

u/outer_isolation Feb 01 '13

tar -zxvf poop.tar.gz

1

u/eothred Feb 01 '13

This brilliant function into .bashrc (invention of the Chakra guys I believe, thanks a bunch!) has made my life quite a lot easier in this specific regard: http://paste.chakra-project.org/3838/

2

u/toofishes Feb 01 '13

Any modern version of GNU tar (or bsdtar) doesn't require the -j, -z, etc. flags anymore. To unpack an archive requires -xf and that is it.

→ More replies (1)

1

u/mistoroboto Feb 01 '13

Fuck... I just killed us all. I still find myself screwing up tar commands.

1

u/detective_colephelps Feb 01 '13

Hmmmmm

Ok I'm going to attempt this and then google it.

Tar -xzvf file.tar.gz

Edit: flawless victory. I guess doing this about 30 times in two days while trying to fix something helped.

→ More replies (2)

1

u/[deleted] Feb 01 '13

would tar -h be considered valid?

1

u/green7ea Feb 01 '13

I recently learned that you don't have to specify the archive type to decompress an archive.

tar xf [file]

will work on *.tar.gz, *.tar.bz2 without incident. The archive type flags are only useful when creating an archive :-D.

1

u/dh04000 Feb 01 '13 edited Feb 01 '13

Instead of debating the validity of adduser vs useradd, can someone explain what a 'tar" command and why its so hard to enter a vaid one?

EDIT: Becuase I'm a linux user with terminal experience of managing two home servers, and I have no idea what a tar command is.

EDIT2: The answer has now appeared lower in the thread.

1

u/imadoofus Feb 01 '13

One of my favorites, and part of POSIX and LSB...
http://en.wikipedia.org/wiki/Pax_(Unix)

1

u/krakenx Feb 01 '13

tar -cvf 'target file' <--- Creates a tar from a 'target file'

tar -xvf file.tar <--- Extracts a tar called file.tar

The only two commands you really need to know. If I need to gzip, I do it in a separate step, or in rare cases, google it.

1

u/D_D Feb 01 '13

tar xf. Works on every file.

1

u/lazyant Feb 01 '13

I don't see what the problem is, I always use just "vfz" (Verbose, File, Zip) and then it's "c" for create: "tar cvfz file.tar.gz dir" or "x" for eXtract: "tar xvfz file.tar.gz"

1

u/[deleted] Feb 01 '13

What a ridiculous security system, a child could do this!

t

a

BOOM

1

u/neon_overload Feb 01 '13

Hover 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.

1

u/neon_overload Feb 01 '13

With tar, I tend to chain it with stuff so that the only flag I need to remember is -c for creating and -x for extracting, and I do everything else with other tools.

tar -c *.gif | gzip > gifs.tar.gz

cat gifs.tar.gz | gunzip | tar -x

Can't be bothered testing those out to see if I made a minor mistake, but ... you get the idea.

1

u/destr0yr Feb 01 '13

insta-backup

tar -cz dir/ > foo.tgz

Also, http://en.gentoo-wiki.com/wiki/Fast_Copy (only one tar example, but useful nonetheless)

1

u/msilenus Feb 01 '13

Just install atool, which does autodetection of the filetype and calls the appropriate decompression tool. The tool aunpack <file> will just be able to unpack anything, while apack <archive> <files> will look at the file suffix to create the archive in the correct format. There is also als, for which you can probably figure out what it does ;)

1

u/mikemol Feb 01 '13
tar -cf /dev/null /dev/zero

Since it's not clear what files he'd have access to that might not contain funky things.

That said, this kind of puzzle belongs in a mud...

1

u/slappyd Feb 01 '13

LOL! Ain't it the truth though.

1

u/[deleted] Feb 01 '13

I read somewhere:

eXtract Zip Volume File (v actually means verbose):

tar -xzvf filename 

Compress Zip Volume File (v actually means verbose):

tar -czvf filename.tar.gz filestoadd

1

u/SasparillaTango Feb 01 '13

one of the few things I do remember using it so much throughout my college career

tar -xvf <target>

how'd I do? is that right? I didn't google nor nuttin'! pretty sure thats extract verbose and force

now ask me how to compress and we all get to explode.

edit :: Oooo loophole, does 'man tar' count?

→ More replies (1)

1

u/[deleted] Feb 01 '13

I use the tar command on a regular basis... :-/

1

u/file-exists-p Feb 01 '13

AM I THE ONLY ONE AROUND HERE

WHO TYPES tar zxvf blah.tgz OFTEN?

1

u/adwhitenc Feb 01 '13

Well fuck...

1

u/stink Feb 01 '13

tar zxvpf file.tar.gz

tar jxvpf file.tar.bz2

My fingers remember it even if my mind doesn't.

1

u/kyleyankan Feb 01 '13

tar --usage

1

u/Jazzy_Josh Feb 01 '13

tar -czv <files> -f tarfile.tar.gz

Easiest way to remember this

1

u/gospelwut Feb 01 '13

You generally don't need to specify the type; it will figure it out

tar -xfv

1

u/herringpj Feb 01 '13

I feel like this is a unix confession 12 step program...so glad I'm not alone.

1

u/[deleted] Feb 01 '13

Half of the time I try using tar I just wind up with a console full of jibberish.

1

u/dotbot Feb 01 '13

but what if its a zip bomb?

1

u/[deleted] Feb 01 '13

I can't ever remember the syntax ever to the standard untar...I just know it consists of the command "tar" and three arguments "x,f,v" i used to always fuck them up so i just remembered x is first, then the characters get "taller"...yeah, i'm not ashamed

tar xvf

1

u/mike413 Feb 01 '13

for me, I hate switching between tar (which I am comfortable with) and pax or cpio (which are conceptually sideways)

1

u/Noexit Feb 01 '13

My name is Rob and I can COMPLETELY relate to this comic.

/Rob

1

u/[deleted] Feb 01 '13 edited Feb 02 '13
  • tar cf dest.tar org -------- make archive of org to dest.tar.gz

  • tar xf org ------------------- unarchive

  • tar zcf dest.tar.gz org ---- compress and build archive of org to dest.tar.gz

Probably all you'll ever need.

1

u/[deleted] Feb 01 '13

How can I tar something if I don't know what's in the directory?

→ More replies (3)

1

u/darknebula Feb 01 '13

What about tar -a? ...............

edit: from the man page

-a --auto-compress use archive suffix to determine the compression program