this post was submitted on 06 Jun 2024
930 points (99.1% liked)

linuxmemes

21172 readers
909 users here now

Hint: :q!


Sister communities:


Community rules (click to expand)

1. Follow the site-wide rules

2. Be civil
  • Understand the difference between a joke and an insult.
  • Do not harrass or attack members of the community for any reason.
  • Leave remarks of "peasantry" to the PCMR community. If you dislike an OS/service/application, attack the thing you dislike, not the individuals who use it. Some people may not have a choice.
  • Bigotry will not be tolerated.
  • These rules are somewhat loosened when the subject is a public figure. Still, do not attack their person or incite harrassment.
  • 3. Post Linux-related content
  • Including Unix and BSD.
  • Non-Linux content is acceptable as long as it makes a reference to Linux. For example, the poorly made mockery of sudo in Windows.
  • No porn. Even if you watch it on a Linux machine.
  • 4. No recent reposts
  • Everybody uses Arch btw, can't quit Vim, and wants to interject for a moment. You can stop now.

  • Please report posts and comments that break these rules!

    founded 1 year ago
    MODERATORS
    you are viewing a single comment's thread
    view the rest of the comments
    [–] AVincentInSpace@pawb.social 11 points 5 months ago (2 children)

    If you download and extract the tarball as two separate steps instead of piping curl directly into tar xz (for gzip) / tar xj (for bz2) / tar xJ (for xz), are you even a Linux user?

    [–] PlexSheep@infosec.pub 13 points 5 months ago (1 children)

    I download and then tar. Curl pipes are scary

    [–] AVincentInSpace@pawb.social 4 points 5 months ago* (last edited 5 months ago) (2 children)

    They really, really aren’t. Let’s take a look at this command together:

    curl -L [some url goes here] | tar -xz
    

    Sorry the formatting's a bit messy, Lemmy's not having a good day today

    This command will start to extract the tar file while it is being downloaded, saving both time (since you don’t have to wait for the entire file to finish downloading before you start the extraction) and disk space (since you don’t have to store the .tar file on disk, even temporarily).

    Let’s break down what these scary-looking command line flags do. They aren’t so scary once you get used to them, though. We’re not scared of the command line. What are we, Windows users?

    • curl -L – tells curl to follow 3XX redirects (which it does not do by default – if the URL you paste into cURL is a URL that redirects (GitHub release links famously do), and you don’t specify -L, it’ll spit out the HTML of the redirect page, which browsers never normally show)
    • tar -x – eXtract the tar file (other tar “command” flags, of which you must specify exactly one, include -c for Creating a tar file, and -t for Testing a tar file (i.e. listing all of the filenames in it and making sure their checksums are okay))
    • tar -z – tells tar that its input is gzip compressed (the default is not compressed at all, which with tar is an option) – you can also use -j for bzip2 and -J for xz
    • tar -f which you may be familiar with but which we don’t use here – -f tells tar which file you want it to read from (or write to, if you’re creating a file). tar -xf somefile.tar will extract from somefile.tar. If you don’t specify -f at all, as we do here, tar will default to reading the file from stdin (or writing a tar file to stdout if you told it to create). tar -xf somefile.tar (or tar -xzf somefile.tar.gz if your file is gzipped) is exactly equivalent to cat somefile.tar.gz | tar -xz (or tar -xz < somefile.tar – why use cat to do something your shell has built-in?)
    • tar -v which you may be familiar with but which we don’t use here – tells tar to print each filename as it extracts the file. If you want to do this, you can, but I’d recommend telling curl to shut up so it doesn’t mess up the terminal trying to show download progress also: curl -L --silent [your URL] | tar -xvz (or -xzv, tar doesn’t care about the order)

    You may have noticed also that in the first command I showed, I didn’t put a - in front of the arguments to tar. This is because the tar command is so old that it takes its arguments BSD style, and will interpret its first argument as a set of flags regardless of whether there’s a dash in front of them or not. tar -xz and tar xz are exactly equivalent. tar does not care.

    [–] PlexSheep@infosec.pub 3 points 4 months ago (1 children)

    Thanks for the explanation, I might use more pipes now. Is it correct, that tar will restore the files in the tarball in the current directory?

    [–] AVincentInSpace@pawb.social 1 points 4 months ago

    Yes. You can specify tar -C somedir if you want it to extract them somewhere else.

    As a rule of thumb, I always extract my tarballs in a newly created, empty directory, just in case whoever packed it didn't put all its files in a subdir

    [–] beeng@discuss.tchncs.de 2 points 4 months ago

    It's not scary from the flags, but rather what is inside the tar/zip.

    [–] brian@programming.dev 2 points 4 months ago

    the problem is if the connection gets interrupted your progress is gone. you download to a file first and it gets interrupted, you just resume the download later