Spyke
feddit.nl

Depends. Is it GNU tar, BSD tar or some old school Unix tar?

Double hyphen "long options" are a typical GNU thing.

46

Yes, the terse Unix version, which needs to be supported for compatibility, and the more readable GNU long option

10
feddit.nl
~# tar -h
tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options
Try 'tar --help' or 'tar --usage' for more information.
***********************************************
WARNING: Self destruct sequence initiated
***********************************************

34
sopuli.xyz

A little trick I learned on here was to imagine yourself as a little evil man saying "Extract ze files!" in a German accent. Extract ze files >>> xzf.

106
Ziixereply
lemmy.dbzer0.com

That sounds a lot like Czech, "ze" means "from" if you translate it into English

7
chellomerereply
lemmy.world

Then comes a .tar.bz2 file along and you're screwed. xtract je vucking file?

Pro tip: -z, -j are not needed by tar anymore since many years, tar will autodetect what compression was used if your distro is anything remotely modern.

28

Pro tip: -z, -j are not needed by tar anymore since many years, tar will autodetect what compression was used if your distro is anything remotely modern.

😵

21
aardreply

You still might want to do something like alias pbtar='tar --use-compress-prog=pbzip2 to easily use pbzip2 - unless you have an ancient system that'll speed things up significantly. And even if you don't it'd be nice to use it for creation - to utilize more than one core the archive needs to be created for parallel extraction.

5
lemmy.world

If you can't tar to a pipe into ssh to a remote host and untar into an arbitrary location there, are you really using Unix?

50
Oha
lemmy.ohaa.xyz

I remember those 2 and thats all I need.
tar -extrakt ze file
tar -compress ze file

48

Tar Xtract Ze Vucking File

Edit: apparently someone else already mentioned this, oops

26
lemmy.world

tar -extract -any -file is easier, auto detect the compression based on filename.

13
exureply
feditown.com

I think GNU tar automatically detects the compression, making -a unnecessary in that case.

7

And -z. tar -xf foo.tar.{gz,xz,zstd,...} will work perfectly fine.

3
lemmy.dbzer0.com

Nope - it was Unix not Linux. The minus makes the command invalid on many Unix versions of tar (though most modern BSD versions allow it)

4

For GNU tar it is, for any other version I would not be so sure. Especially when disabling an atomic bomb.

18
lemmy.world

tar xvf somearchive.tar

Is that right? )= I'm scared I lost.

32
bdonvrreply
thelemmy.club

user@server:~> tar xvf somearchive.tar

tar: somearchive.tar: Cannot open: No such file or directory

tar: Error is not recoverable: exiting now

29
iusearchlinux.fyi

false

tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options
Try 'tar --help' or 'tar --usage' for more information.
zsh: exit 2     tar
52

OK now I have to escape to really smart assery and assume that's what I meant the whole time ;)

Edit code 2 describes something that went wrong - but that something telling you that it went wrong was the tar binary which therefor most have been valid to evaluate that!

Under no circumstances did I assume that the hint towards help itself would've been an exit code 0, no sir!

To be honest: if I'd designed that bomb it would've exploded in my face for trying to be too clever.

7
lemmy.ml

I know this is a meme, but I actually find tar fairly easy to remember.

tar -xf $archive is extract file

tar -czf $archive dir/ is create zipped (compressed) file and the positional arguments are the files to add to the archive.

And this is 99% of my usage. You can skip -f $archive to use stdin/stdout or use -C to change directory (weird name but logically tar always extracts to the current directory). There is also a flag to list which I always forget and lookup each time, but I list much less often. -v is useful for verbose.

Overall there are much harder commands to remember. find always gets me if I go beyond -name. ps, tree and ls (beyond -Al) always get me to open the man page.

29

There is also a flag to list which I always forget and lookup each time

That would be -t, which I tend to remember as "test", as in testing to see what is inside the archive!

tealdeer is a great program to have installed for easily getting a breakdown of the flags of pretty much any CLI app that at least I can ever think of!

10
personreply
lemm.ee

tldr tar and you might have a chance

13

Normally I would say view the man page (as a command). Though for some reason when making the thinnest distro possible, the OS team at my job got rid of man.

Wtf man.

20

The command that I can never get right the first time is ln. I always end up creating a dead link inside my target folder, even when I read the man page directly prior.

20
infosec.pub

tar xzvf file.tar.gz I got it memorized after installing gentoo over and over again from stage 3 back in 2005

13

I find it's a lot easier if you think of it in term of tapes, which is what it was originally designed for (Tape ARchiver). It's up there with makefiles for an actually really cool concept that nobody appreciates or even necessarily understands now.

(Well, I guess filesystems are the actual cool concept, from the historical perspective, but seeing the interplay with just tapes is the novel part to me)

12
lemmy.world

I wish more people knew about dtrx (Do The Right eXtraction).

11

Ayy Debian has been my main for like ten years. Dtrx is one of the ten things I apt immediately every time I have a re install

6
chellomerereply
lemmy.world

They meant the command dtrx, the combination of dtrx as parameters to tar make no sense. Extract AND append?

3

haha, ok thanks. So https://github.com/dtrx-py/dtrx

I'd initially assumed that it was a mnemonic but yes, listing and appending and extracting together is nonsensical, as tar notes: tar: You may not specify more than one '-Acdtrux', '--delete' or '--test-label' option

1

At some point, I realized tar xf is enough for extracting a file, so that's what I'm always using now.

11

I just remember zxvf, but if I have to do anything else then extract a tar.gz we’re fucked.

7

tar -xvf is the only one I know

And I think it was tar -cvf for creating .tar files?

3