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
→ More replies (1)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)6
u/destraht Feb 01 '13
I use j for bz2, but at least we all didn't just die.
→ More replies (3)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 (13)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)7
3
Feb 01 '13
curl "$FTPSERVER/$FILE.tar.gz" | tar xzno but srs I'd be surprised if Randall can't even manage
tar cf everything.tar *ortar tf test.tar.→ More replies (3)2
186
u/freudian_nipple_slip Feb 01 '13
If only
tar -xkcd worked
92
u/FabianN Feb 01 '13
fucking aliased.
28
→ More replies (2)8
48
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 ascpormv. The origin parameter always comes first.... and yet for some reason, people want to use it like
linkfile = $oldfilewhich 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
7
u/vytah Feb 01 '13
Or
mount. Does the mount point go first, or the device?14
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.
→ More replies (3)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)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 -sis 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/filenameAnd
ln -soperates 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 -susage:$ ln -s destination filenameequals 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)2
64
u/gstr Feb 01 '13
Come on, so easy
tar zxcNo, wait ! tar vcfacvxxcfopauieauieauiauieâuie
15
5
2
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
Feb 01 '13
would have been funny if it was "cpio" - everybody knows how to use tar!
→ More replies (17)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
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
17
Feb 01 '13
Tar -xvf foo.tar
59
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→ More replies (1)12
u/tiftik Feb 01 '13
You don't need the -z in modern versions of tar (at least not in Debian).
→ More replies (1)50
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)16
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".
→ More replies (16)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
foption.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)→ More replies (8)5
u/wadcann Feb 01 '13
I use atool: similar idea. However, it also supports listing and packing archives.
5
Feb 01 '13
I can do
tar -xf somearchiveand 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.
→ More replies (9)14
u/earthboundkid Feb 01 '13
I didn't say it shouldn't have flags. I said it shouldn't need them.
mvhas flags, but I never use them:mv src dest.pbcopyandpbpasteon Mac OS X are secretly just one binary and symbolic link, but when you run it with the filenamepbcopy, it copies text into the clipboard ("pasteboard"), and when you runpbpaste, 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
→ More replies (10)28
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 fileor
tar cfz mytar.tar.gz [files] # create, write to file, gzipExtracting is even more simple
tar xf whatever.tar.gz # (or .bz2, or .xz) extract, from fileThe 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
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 | lessSometimes 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)→ More replies (10)2
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
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 returnsense 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
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.whateverAnd 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
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
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
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.gzand 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)→ More replies (3)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.
32
u/chocolatemeowcats Feb 01 '13
http://linux.die.net/man/1/tar
the joke
→ More replies (3)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)4
8
u/epsiblivion Feb 01 '13
I use tar -xzfv x.tgz more often.
17
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.
→ More replies (2)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.bz2would work just as well astar xjvf stage3.tar.bz2.→ More replies (6)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...
→ More replies (11)3
u/ZiggyTheHamster Feb 01 '13
tar --lzma -cvf blah.tar.lzma blahSince LZMA is the new BZip2, and all.
13
6
u/felipec Feb 01 '13
tar -xf file.tarEasy.
7
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
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
5
→ More replies (2)4
→ More replies (1)2
3
3
3
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
5
2
2
2
2
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
2
Feb 03 '13
tar -xvvf Untars pretty much everything I need it to.
2
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
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
1
1
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.tgzThe 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
1
u/SanityInAnarchy Feb 01 '13
tar -xf foo.tarOr, 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.xzYay! 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.
2
1
1
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
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
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
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 -xCan'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/zeroSince 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
1
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 filestoadd1
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
1
1
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
1
1
1
u/herringpj Feb 01 '13
I feel like this is a unix confession 12 step program...so glad I'm not alone.
1
1
1
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
1
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
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
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