Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
sebastiancarlos ( sebastiancarlos@lemmy.sdf.org )  to Linux@lemmy.mlEnglish · 3 年前

How to write a 'tar' command

lemmy.sdf.org

message-square
107
link
fedilink
547

How to write a 'tar' command

lemmy.sdf.org

sebastiancarlos ( sebastiancarlos@lemmy.sdf.org )  to Linux@lemmy.mlEnglish · 3 年前
message-square
107
link
fedilink
alert-triangle
You must log in or register to comment.
  • perviouslyiner ( perviouslyiner@lemm.ee ) 
    link
    fedilink
    English
    arrow-up
    127
    ·
    3 年前

    easy

    • bdonvr ( bdonvr@thelemmy.club ) BannedBanned
      link
      fedilink
      arrow-up
      46
      ·
      3 年前

      It should be a crime to directly link XKCDs images without the corresponding page.

      https://xkcd.com/1168/

    • TheSaneWriter ( TheSaneWriter@lemmy.thesanewriter.com ) 
      link
      fedilink
      English
      arrow-up
      6
      ·
      3 年前

      I understand and sympathize with Rob on a spiritual level.

  • Oha ( Oha@lemmy.ohaa.xyz ) 
    link
    fedilink
    arrow-up
    65
    ·
    3 年前

    I remember it like this:
    tar -extract ze file
    and
    tar -compress ze file

    • Atemu ( Atemu@lemmy.ml ) 
      link
      fedilink
      arrow-up
      41
      ·
      3 年前

      And also tar -the fuck is in this file

    • exscape ( exscape@kbin.social ) 
      link
      fedilink
      arrow-up
      15
      ·
      3 年前

      z is for gz files only though, there are plenty of others. xf autodetects and works with all of them (with GNU tar att least).

    • fiat_lux ( fiat_lux@kbin.social ) 
      link
      fedilink
      arrow-up
      10
      ·
      3 年前

      Same. This pic has been helpfully living in my memory for probably a decade.

  • blackstrat ( blackstrat@lemmy.fwgx.uk ) 
    link
    fedilink
    English
    arrow-up
    38
    ·
    3 年前

    I hope whoever thought -l should mean “check links” instead of list has a special place in Hell set aside for them.

    I have no idea what print a message if not all links are dumped even means.

    • happyhippo ( happyhippo@feddit.it ) 
      link
      fedilink
      arrow-up
      7
      ·
      3 年前

      Was gonna say this. Why TF is list not -l as…everywhere else?

  • aard ( aard@kyu.de ) 
    link
    fedilink
    arrow-up
    19
    ·
    3 年前

    You also don’t need the dash for the short options.

    Also, if you’re compressing with bzip2 and have archives bigger than a few megabytes I’ll like you a lot more if you do it with --use-compress-prog=pbzip2

    • sebastiancarlos ( sebastiancarlos@lemmy.sdf.org ) OP
      link
      fedilink
      arrow-up
      22
      ·
      3 年前

      You also don’t need the dash for the short options.

      True, but I refuse to entertain such a non-standard option format. It’s already enough to tolerate find’s.

      • aard ( aard@kyu.de ) 
        link
        fedilink
        arrow-up
        16
        ·
        3 年前

        Technically the notation with dashes is the non-standard one - the dash form is a GNU addition. A traditional tar on something like Solaris or HP-UX will throw an error if you try the dash notation.

        • sebastiancarlos ( sebastiancarlos@lemmy.sdf.org ) OP
          link
          fedilink
          arrow-up
          19
          ·
          3 年前

          It’s also traditional to eat raw meat, but we discovered fire at some point.

          • aard ( aard@kyu.de ) 
            link
            fedilink
            arrow-up
            9
            ·
            3 年前

            Don’t try to take my raw ground pork away from me.

            • lvxferre ( lvxferre@lemmy.ml ) deleted by creator
              link
              fedilink
              arrow-up
              3
              ·
              3 年前

              my raw ground pork away from me.

              Who are you, the Mett demon?
              Matt Damon made out of mett\

              (It works great with beef, too. Bonus points for the raw yolk over it. If not homemade though there’s literally one bar that I trust with this, salmonella is not fun.)

              • aard ( aard@kyu.de ) 
                link
                fedilink
                arrow-up
                2
                ·
                3 年前

                Not enough onions. Your average mettigel has better mett/onion ratio.

            • Damage ( Damage@feddit.it ) 
              link
              fedilink
              arrow-up
              3
              ·
              3 年前

              I got toxoplasmosis that way

            • Leo ( leo@lemmy.linuxuserspace.show ) 
              link
              fedilink
              English
              arrow-up
              2
              ·
              3 年前

              That’s an audible “yuck” from me, man. Well done!

              • Björn ( bjoern_tantau@swg-empire.de ) 
                link
                fedilink
                arrow-up
                4
                ·
                3 年前

                Looks like you Mett your match.

              • Blizzard ( Blizzard@lemmy.zip ) 
                link
                fedilink
                English
                arrow-up
                3
                ·
                3 年前

                Can’t be well done if it’s raw.

        • TheSaneWriter ( TheSaneWriter@lemmy.thesanewriter.com ) 
          link
          fedilink
          English
          arrow-up
          1
          ·
          3 年前

          I like the dashes, they make the options look like options to me.

    • Programmer Belch ( programmer_belch@lemmy.dbzer0.com ) 
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 年前

      I think the -j also compresses with bzip2 but I’m not sure if this is defined behavior or just a shortcut

      • aard ( aard@kyu.de ) 
        link
        fedilink
        arrow-up
        3
        ·
        3 年前

        Yes, but I’m asking you to use pbzip. bzip at best utilizes one core, both for packing and unpacking. pbzip uses as many cores as IO bandwith allows - with standard SATA SSDs that’s typically around 30.

        pbzip can only utilize multiple cores if the archive was created with it as well.

        • Programmer Belch ( programmer_belch@lemmy.dbzer0.com ) 
          link
          fedilink
          English
          arrow-up
          2
          ·
          3 年前

          Does something similar happen using xz?

          • Programmer Belch ( programmer_belch@lemmy.dbzer0.com ) 
            link
            fedilink
            English
            arrow-up
            2
            ·
            3 年前

            I’ve searched for it and xz also doesn’t use multithreading by default, you can change the program tar uses to compress by passing the -I option. For xz using all possible CPU threads:

            tar -cv -I 'xz -6 -T0' -f archive.tar.xz [list of directories]

            The number indicates the compression ratio, the higher the number, the more compressed the archive will be but it will cost more in terms of memory and processing time

            • TheSaneWriter ( TheSaneWriter@lemmy.thesanewriter.com ) 
              link
              fedilink
              English
              arrow-up
              1
              ·
              3 年前

              Thanks for answering your own question, this is useful information.

      • tony ( tony@lemmy.hoyle.me.uk ) 
        link
        fedilink
        English
        arrow-up
        2
        ·
        3 年前

        There’s nothing technically wrong with using xjf rather than xzf, but it’ll bite you if you ever use a non-linux platform as it’s a GNU extension. I’m not even sure busybox tar supports it.

  • wvstolzing ( walthervonstolzing@lemmy.ml ) 
    link
    fedilink
    arrow-up
    17
    ·
    3 年前

    Those are straightforward; it’s the remaining 900 options that are confusing. I always need to look up --excludes and always get --directory wrong, somehow.

  • Zacryon ( Zacryon@feddit.de ) 
    link
    fedilink
    arrow-up
    17
    ·
    3 年前

    Ah yes, that’s the linux community as I know it. There is one thing someone wants to achieve and dozens of ways to do it. ;)

    • /home/pineapplelover ( pineapplelover@lemm.ee ) 
      link
      fedilink
      arrow-up
      5
      ·
      3 年前

      Nah I just use 7z

  • miniu ( miniu@programming.dev ) 
    link
    fedilink
    arrow-up
    16
    ·
    3 年前

    Why when explaining, giving examples of shell command are people so often providing shortened arguments. It makes it all seam like some random letters you have to remeber by heart. Instead of -x just write --extract. If in the end they endup using the tool so often they need to write it fast they’ll check the shortcuts.

    • catacomb ( catacomb@beehaw.org ) 
      link
      fedilink
      English
      arrow-up
      7
      ·
      3 年前

      I don’t even mind the shortened arguments too much, though it doesn’t help. It’s more that every example seems to smush them together into a string of letters.

      I would have found

      tar -x -f pics.tar ./pics

      to be clearer when I was learning. There’s plenty of commands which allow combining flags but every tar tutorial seems to do it from the beginning.

    • ExLisper ( ExLisper@linux.community ) 
      link
      fedilink
      English
      arrow-up
      3
      ·
      3 年前

      They are random letters you have to learn by hard. No one uses the long form. If someone just needs to use it one time they will copy the line from somewhere.

    • bullshitter ( bullshitter@lemm.ee ) 
      link
      fedilink
      arrow-up
      2
      ·
      3 年前

      Does every Linux command have options as words instead of single letters?

      • MonkderZweite ( MonkderZweite@feddit.ch ) 
        link
        fedilink
        arrow-up
        6
        ·
        3 年前

        Tar is as old as IT, that’s why it’s syntax is a bit special.

        • barsoap ( barsoap@lemm.ee ) 
          link
          fedilink
          arrow-up
          4
          ·
          3 年前

          tar -xf is not really special combining short options isn’t uncommon.

          Where tar is nonstandard is that you can leave out the -, tar xf is actually how POSIX specifies it. And we’ve kinda come full circle on that one with many modern utilities using a command syntax, you can read tar xf as “tar extract file” just as you can read git pull as, well, “git pull”.

          If you want to see a standard command with truly non-standard syntax have a look at dd.

          • MonkderZweite ( MonkderZweite@feddit.ch ) 
            link
            fedilink
            arrow-up
            1
            ·
            3 年前

            Nono, dash-parameters are new in fancy GNU tar. And POSIX is not old.

      • sonnenzeit ( sonnenzeit@feddit.de ) 
        link
        fedilink
        arrow-up
        3
        ·
        3 年前

        Many do as it’s considered good practice, but it’s not guaranteed, it just depends on the individual command (program). Usually you can use the --help option to see all the options, so for instance tar --help.

      • Zangoose ( Zangoose@lemmy.one ) 
        link
        fedilink
        arrow-up
        2
        ·
        3 年前

        Most commands will have expanded arguments started with 2 dashes that usually look like ‘–verbose-name-of-option’, they’re usually listed in the man page/documentation along with the abbreviated letter version

  • gibson ( gibson@sopuli.xyz ) 
    link
    fedilink
    arrow-up
    12
    ·
    3 年前

    I don’t think tar is actually hard, we are just in the time where we externalize more information into resources such as Google. Its the same reason why younger people don’t remember routes by name or cardinal direction as much anymore.

    side note: $ tldr is much better than man for just getting common stuff done.

    • Aatube ( Aatube@kbin.social ) 
      link
      fedilink
      arrow-up
      8
      ·
      3 年前

      Yes, but still tar options are kinda janky.

  • d00phy ( d00phy@lemmy.ml ) 
    link
    fedilink
    arrow-up
    11
    ·
    3 年前

    The “-“ is often not necessary. I use it as a guide to see how long the person running tar has been using it.

    Example:

    tar -xf file.tar == tar xf file.tar

    • Fushuan [he/him] ( fushuan@lemm.ee ) 
      link
      fedilink
      English
      arrow-up
      5
      ·
      3 年前

      They are functionally flags though and uniletter flags should be preceded by a ‘-’, so I would still prefer to have the ‘-’ written, because it conforms with the standard.

    • Ricaz ( Ricaz@lemmy.ml ) 
      link
      fedilink
      arrow-up
      2
      ·
      3 年前

      But muh POSIX

  • 520 ( 520@kbin.social ) 
    link
    fedilink
    arrow-up
    9
    ·
    3 年前

    Simple:

    tar -(whatever options you want here, my go to is xvzf or cvzf) archive-name.tar file/folder-to-compress

    • cooopsspace ( cooopsspace@infosec.pub ) 
      link
      fedilink
      English
      arrow-up
      17
      ·
      3 年前

      Create ze vuking file

      Xtraxt ze vuking file

    • barkingspiders ( barkingspiders@infosec.pub ) 
      link
      fedilink
      English
      arrow-up
      4
      ·
      3 年前

      tar can do things other than this?

      • 520 ( 520@kbin.social ) 
        link
        fedilink
        arrow-up
        2
        ·
        3 年前

        Oh I’m aware, I’m just saying this is what I normally do with it

        • barkingspiders ( barkingspiders@infosec.pub ) 
          link
          fedilink
          English
          arrow-up
          3
          ·
          3 年前

          I’m sorry, I was trying to be silly and poke fun at how most of us just use the one or two tar commands and it totally didn’t translate in text like it did my head. Have a wonderful day good internet stranger.

  • anteaters ( anteaters@feddit.de ) 
    link
    fedilink
    arrow-up
    7
    ·
    3 年前

    tar is just the worst shell command in existence. Why do people still bother with it?

    • PuppyOSAndCoffee ( PuppyOSAndCoffee@lemmy.ml ) deleted by creator
      link
      fedilink
      arrow-up
      6
      ·
      3 年前

      Because it is faster to transport one big ass tar than 10k individual files, and compression is waste of time.

    • GiantRobotTRex ( GiantRobotTRex@lemmy.sdf.org ) 
      link
      fedilink
      arrow-up
      3
      ·
      3 年前

      What do you use instead?

      • anteaters ( anteaters@feddit.de ) 
        link
        fedilink
        arrow-up
        3
        ·
        3 年前

        I avoid it and use zip or 7z if I can. But for some crazy reason some people stil insist on using that garbage tool and I have no idea why.

        • duncesplayed ( duncesplayed@lemmy.one ) 
          link
          fedilink
          English
          arrow-up
          7
          ·
          3 年前

          Are zip and 7z really that much easier?

          tar cf foo.tar.xz wherever/
          zip -r foo.zip wherever/
          7z a foo.7z wherever/
          

          I get that tar needs an f for no-longer-relevant reasons whereas other tools don’t, but I never understood the meme about it beyond that. Is c for “create” really that much worse than a for “add”?

          • anteaters ( anteaters@feddit.de ) 
            link
            fedilink
            arrow-up
            1
            ·
            3 年前

            7z x to extract makes sense. unzip even more. No need for crazy mnemonics or colorful explanation images. It’s complete nonsense that people are ok with that.

        • aard ( aard@kyu.de ) 
          link
          fedilink
          arrow-up
          6
          ·
          3 年前

          If you want to do more than just “pack this directory up just as it is” you’ll pretty quickly get to the limits of zip. tar is way more flexible about selecting partial contents and transformation on packing or extraction.

          • anteaters ( anteaters@feddit.de ) 
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            3 年前

            100% of tarballs that I had to deal with were instances of “pack this directory up just as it is” because it is usually people distributing source code who insist on using tarballs.

        • TimeSquirrel ( TimeSquirrel@kbin.social ) 
          link
          fedilink
          arrow-up
          2
          ·
          3 年前

          Because everyone else does, and if everyone else does, then I must, and if I do, then everyone else must, and then everyone else does.

          Repeat loop.

          • anteaters ( anteaters@feddit.de ) 
            link
            fedilink
            arrow-up
            1
            ·
            3 年前

            For all I care it goes on the same garbage dump as LaTeX.

            • Baut [she/her] auf. ( BautAufWasEuchAufbaut@lemmy.blahaj.zone ) 
              link
              fedilink
              arrow-up
              5
              ·
              3 年前

              I think that’s pretty mean towards the free software developers spending their spare time on Latex and the GNU utils.
              I and many academics use Latex, and I personally am very happy to be able to use something which is plain text and FLOSS.
              I also don’t see your problems with tar; it does one thing and it does it good enough.

              • anteaters ( anteaters@feddit.de ) 
                link
                fedilink
                arrow-up
                1
                ·
                edit-2
                3 年前

                I also don’t see your problems with tar; it does one thing and it does it good enough.

                The problem is the usage of the tool which people invent different mnemonics for because it’s UX is stuck in 1986 and the only people who remember the parameters are those who use it daily.

                Similar thing for LaTeX: it’s so absurdly crusty and painful to work with it’s only used by people who have no alternative.

                //ETA
                Also, I don’t want to be mean towards the maintainers of LaTeX. I’m sorry if I made any LaTeX maintainer reading this upset or feel inferior. Working on the LaTeX code is surely no easy endeavour and people who still do that in 2023 deserve a good amount of respect.

                But everytime I had to work with LaTeX or any of its wrappers was just pure frustration at the usage and the whole project. The absolute chaos of different distributions, templates, classes and whatnot is something I never want to experience again.

        • PuppyOSAndCoffee ( PuppyOSAndCoffee@lemmy.ml ) deleted by creator
          link
          fedilink
          arrow-up
          2
          ·
          3 年前

          You do you. Compression is waste of time; storage is cheap in that you can get more, but time? Time, you never get back.

          • russjr08 ( russjr08@outpost.zeuslink.net ) 
            link
            fedilink
            English
            arrow-up
            5
            ·
            3 年前

            Yes, and I’d rather not have my time wasted by waiting on thousands of small files transfer, rather than just compressing it and the time spent of one file transferring being much smaller.

            • PuppyOSAndCoffee ( PuppyOSAndCoffee@lemmy.ml ) deleted by creator
              link
              fedilink
              arrow-up
              1
              ·
              3 年前

              Tar achieves the same effect without time to compress and decompress.

    • Kait Richardson ( qirenni@mastodon.social ) 
      link
      fedilink
      arrow-up
      0
      ·
      3 年前

      @anteaters @sebastiancarlos a little knowledge really is a dangerous thing

  • Gamey ( Gamey@feddit.de ) 
    link
    fedilink
    arrow-up
    7
    ·
    3 年前

    I use Linux for years and still Google every time I have to use it!

    • darklamer ( darklamer@lemmy.dbzer0.com ) deleted by creator
      link
      fedilink
      arrow-up
      5
      ·
      edit-2
      10 个月前

      deleted by creator

      • TheSaneWriter ( TheSaneWriter@lemmy.thesanewriter.com ) 
        link
        fedilink
        English
        arrow-up
        4
        ·
        3 年前

        For me it’s because I don’t use it very often, mostly just archiving stuff every few months or so.

        • Gamey ( Gamey@feddit.de ) 
          link
          fedilink
          arrow-up
          2
          ·
          3 年前

          Yea, I use it from time to time but not very often and the syntax are as unintuitive as it gets (at least to my brain)

  • arc ( arc@lemm.ee ) 
    link
    fedilink
    arrow-up
    7
    ·
    3 年前

    I know the basics off by heart. Not the hardest command syntax to learn all things considered.

    The most annoying would be the growing collection of “uber commands” which are much more of a pain in the ass - aws, systemctl, docker, kubectl, npm, cargo, etc. - the executable has potentially dozens of subcommands, each of which has dozens of parameters.

    • stilgar [he/him]  ( stilgar@infosec.pub ) 
      link
      fedilink
      English
      arrow-up
      3
      ·
      3 年前

      These “uber commands” tend to be much better since they are more explorable with --help explanations and readable flags.

      Much better than the random jumble of characters you’re expected to have memorised for awk, sed, find et al.

    • emptiestplace ( emptiestplace@lemmy.ml ) 
      link
      fedilink
      arrow-up
      3
      ·
      3 年前

      PowerShell is so much worse.

      • arc ( arc@lemm.ee ) 
        link
        fedilink
        arrow-up
        4
        ·
        3 年前

        Powershell is horrible all right. What annoys me is they alias ls, dir and other common commands onto commands which don’t act or behave in the same way at all. I just run bash or command prompt rather than deal with the bs of powershell.

  • Blackmist ( Blackmist@feddit.uk ) 
    link
    fedilink
    English
    arrow-up
    6
    ·
    3 年前

    Yes, that’s all very well, but you’ll still need to find that image the next time you want to use it.

  • SokathHisEyesOpen ( Anticorp@lemmy.ml ) 
    link
    fedilink
    English
    arrow-up
    6
    ·
    3 年前

    What is “listing”?

    • peppy ( peppy@lemmy.ml ) 
      link
      fedilink
      arrow-up
      11
      ·
      3 年前

      lists the files in the archive. So you don’t need to extract the entire archive. Useful for huge archives.

      • SokathHisEyesOpen ( Anticorp@lemmy.ml ) 
        link
        fedilink
        English
        arrow-up
        5
        ·
        3 年前

        Thanks!

Linux@lemmy.ml

linux@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !linux@lemmy.ml

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word “Linux” in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

  • Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
  • No misinformation
  • No NSFW content
  • No hate speech, bigotry, etc

Related Communities

  • !opensource@lemmy.ml
  • !libre_culture@lemmy.ml
  • !technology@lemmy.ml
  • !libre_hardware@lemmy.ml

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1 user / day
  • 1 user / week
  • 1 user / month
  • 5.27K users / 6 months
  • 1.31K local subscribers
  • 68.1K subscribers
  • 8.11K Posts
  • 108K Comments
  • Modlog
  • mods:
  • AgreeableLandscape ( AgreeableLandscape@lemmy.ml ) deleted by creator
  • nooter692 ( nooter692@lemmy.ml ) 
  • MarcellusDrum ( MarcellusDrum@lemmy.ml ) 
  • Arthur Besse ( cypherpunks@lemmy.ml ) 
  • Cyclohexane ( cyclohexane@lemmy.ml ) 
  • d3Xt3r ( d3Xt3r@lemmy.nz ) deleted by creator
  • BE: 0.19.21
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code