source

img title=“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.”

    • DefederateLemmyMl
      link
      fedilink
      469 months ago

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

      Double hyphen “long options” are a typical GNU thing.

      • paraphrand
        link
        English
        129 months ago

        That’s why those commands have two?

        • DefederateLemmyMl
          link
          fedilink
          English
          109 months ago

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

        • DefederateLemmyMl
          link
          fedilink
          English
          34
          edit-2
          9 months ago
          ~# 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
          ***********************************************
          

  • Krafty Kactus
    link
    fedilink
    English
    1069 months ago

    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.

  • @olsonexi
    link
    719 months ago

    xtract ze vucking file

    • @chellomere
      link
      289 months ago

      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.

      • @[email protected]
        link
        fedilink
        219 months ago

        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.

        😵

      • aard
        link
        fedilink
        59 months ago

        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.

      • Victor
        link
        29 months ago

        Yeah I usually just do xf. 🤷‍♂️

    • Victor
      link
      109 months ago

      v is just verbose, right?

  • @fubo
    link
    509 months ago

    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?

  • ɐɥO
    link
    fedilink
    489 months ago

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

    • @SirQuackTheDuck
      link
      139 months ago

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

      • exu
        link
        fedilink
        English
        79 months ago

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

    • @[email protected]
      link
      fedilink
      49 months ago

      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)

    • @Aganim
      link
      18
      edit-2
      9 months ago

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

  • @owatnext
    link
    329 months ago

    tar xvf somearchive.tar

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

    • @[email protected]
      link
      fedilink
      29
      edit-2
      9 months ago

      user@server:~> tar xvf somearchive.tar

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

      tar: Error is not recoverable: exiting now

    • Lunya \ she/it
      link
      fedilink
      529 months ago

      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
      
      • @[email protected]
        link
        fedilink
        79 months ago

        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.

  • @[email protected]
    link
    fedilink
    29
    edit-2
    9 months ago

    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.

    • Russ
      link
      fedilink
      English
      109 months ago

      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!

  • @kautau
    link
    279 months ago

    man tar

    “Yeah nvm, we’re fucked”

  • @[email protected]
    link
    fedilink
    English
    209 months ago

    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.

  • @[email protected]
    link
    fedilink
    English
    20
    edit-2
    9 months ago

    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.