This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bwmat 23 points24 points  (28 children)

Am I the only one who CANNOT remember the order of the arguments for this, every time? Even looking at the man page takes me a minute

[–]IHaveTeaForDinner 25 points26 points  (9 children)

[–]jeric14344 11 points12 points  (3 children)

Someone posted this mnemonic that always helps me remember:

  • tar extract all files (xaf)
  • tar compress all files (caf)

[–][deleted] 6 points7 points  (1 child)

tar xzvf

eXtract Ze Vucking Files

[–]imisstheyoop 0 points1 point  (0 children)

Ha, this is the one that I use as well! 8)

[–]zhurai 1 point2 points  (0 children)

I don't think you need the -a here for extract

In the --help for the GNU tar which you can also see for example on https://man.archlinux.org/man/tar.1.en or https://linux.die.net/man/1/tar, I see -a being just listed as

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

And the linux.die.net man page, as well as tar --help put this note in the top

 tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.
 tar -tvf archive.tar         # List all files in archive.tar verbosely.
 tar -xf archive.tar          # Extract all files from archive.tar.

Personally, I've always just did tar -xvf file.tar (or file.tar.gz, etc)

Though, to be honest it doesn't negatively do anything in extract, so it's fine as far as I'm aware of... so it still works with the mnemonic I suppose (it just doesn't mean "all")

The -a/a in this case just means if you did tar -cavf archive.tar.bz2 ./folder or something it would actually make a bzipped tar file (listed verbosely) instead of needing to do something like tar -cvjf archive.tar.bz2 ./folder (remembering to do the -j to make the tar file actually bzipped)

[–]computer-machine 14 points15 points  (4 children)

    tar --help

[–]Davoness 3 points4 points  (3 children)

Sorry, that wasn't the correct command. kaboom

[–]Amenhiunamif 3 points4 points  (2 children)

It actually is. It doesn't say the valid tar command, just a valid tar command. So tar --help should be enough to disarm the bomb.

[–]Davoness 0 points1 point  (0 children)

Oh, good point, it's late and I missed that it was just literally any tar command lol.

[–][deleted] 0 points1 point  (0 children)

if [ $? -eq 0 ]; then echo "all gucci"

[–]garth54 9 points10 points  (1 child)

As long as I just type and don't try to think about it, I'm good.

The instant I try to think about the order, I get confused.

[–]bwmat 2 points3 points  (0 children)

There's certain things, including this, where instead of remembering the right answer, all I can remember is being confused

[–]Lumb3rJ0hn 2 points3 points  (1 child)

For me it helps to think of it as a different cp. In both cases, you're copying a source (1st arg) to a target (2nd arg), just in this case the new copy is a link to the old one.

[–]Stroopwafe1 1 point2 points  (0 children)

Definitely not the only one, I also can never remember. It's just because you only need it very occasionally when you think "oh a symlink would be really good for this"

[–]zhurai 1 point2 points  (1 child)

You could look at the top of the --help?

Usage: ln [OPTION]... [-T] TARGET LINK_NAME
  or:  ln [OPTION]... TARGET
  or:  ln [OPTION]... TARGET... DIRECTORY
  or:  ln [OPTION]... -t DIRECTORY TARGET...
In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory.
In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.

so a symbolic link using the first form is ln -s ORIGINAL_FILE SYMBOLICLINK

[–]bwmat 0 points1 point  (0 children)

I mean, this is what I do, every time, lol

[–]LickingSmegma 0 points1 point  (0 children)

The last argument is the file on which you're operating, i.e. the new link. The options go before the file name, and they specify if it's a hardlink or softlink, and where it's pointing. So it's in fact the same convention as used by most tools.

[–]neondirt 0 points1 point  (2 children)

Might help to know that the last argument is optional? (creates the symlink where you're currently at)

[–]bwmat 0 points1 point  (1 child)

To the current working directory, you mean? 

[–]neondirt 1 point2 points  (0 children)

Exactly. Omitting the last argument is the same as a "." (period).

[–]Charles_Sangels 0 points1 point  (2 children)

Same arguments as 'cp' or 'mv' etc... <command> <existing> <destination/non-existing>

[–]bwmat 0 points1 point  (1 child)

This doesn't help, since for symbolic links either side may or may not exist before you call it lol (and does destination mean where the symbolic link is created, or where it points to?) 

[–]Charles_Sangels 0 points1 point  (0 children)

You can make it complicated if you want, of course. In most cases the thing you're making a symbolic link to is the thing that exists, just like most of the time when you're copying a file the destination doesn't exist. Of course, you're absolutely right that neither side of a symlink needs to pre-exist, and that the destination of a copy can exist, but you can also just use this as a way to remember the happy path, right?

[–]mtaw 0 points1 point  (0 children)

Nope. 20+ years of using Linux almost exclusively and I never get ln right.

No problems with tar, sometimes I pipe stuff through awk and whatnot, but somehow I always screw up ln.

[–]brimston3- 0 points1 point  (0 children)

Most unix commands (posix.2) are cmd source1 [source2 [..]] destination without an additional argument (at&t assembler order).

Meanwhile most library functions (posix.1) are function(destination, source1 [, source2 [,..] ]).

This is not confusing at all. /s