Score:0

Why use tee with wget? Isn't it superfluous?

in flag

So I came across this code for downloading youtube-dl using wget which pipes into tee here: How can I update youtube-dl?

The code being:

wget -O - https://yt-dl.org/downloads/latest/youtube-dl | sudo tee /usr/local/bin/youtube-dl >/dev/null

What is the difference when comparing with the following?:

sudo wget -P /usr/local/bin/ https://yt-dl.org/downloads/latest/youtube-dl

or even for that matter:

sudo wget -O /usr/local/bin/youtube-dl https://yt-dl.org/downloads/latest/youtube-dl

Is there something particular about using wget with tee that I'm missing here? If I've understood correctly the former simply downloads the files and outputs the files being downloaded to standard output which is then piped through tee into the designated file as well as standard output with any additional standard output being redirected to /dev/null. Isn't the former string of code superfluous and overly complicated when the latter two completely suffice?

One more question when on the subject of using tee like this:

Can one not theoretically also replace tee with cat? Like this:

wget -O - https://yt-dl.org/downloads/latest/youtube-dl | sudo cat >/usr/local/bin/youtube-dl

or this:

wget -O - https://yt-dl.org/downloads/latest/youtube-dl | sudo cat /usr/local/bin/youtube-dl

When I do the former I get this output (I've only taken the last three lines):

Saving to: ‘STDOUT’
-                                                                      0%[                                                                                                                                                                     ]       0  --.-KB/s    in 0,003s  
Cannot write to ‘-’ (Success).

And when I do the latter I get the same output just without the "Cannot write to ‘-’ (Success)."

Thanks a ton in advance for any explanation!

Keith5001 avatar
pw flag
youtube-dl -U will do a update
hr flag
When you do `| sudo cat >file`, the `cat` is run with elevated privileges but the redirection (which is the part that requires them) is not. When you so `| sudo cat file` you're writing the contents of `file` to standard output, rather than writing `cat`'s standard input to `file`.
mysterium avatar
in flag
@steeldriver, thanks for the explanation. How should I write it out if I wanted the redirection to have elevated privileges?
Score:3
in flag

The difference is that you don't execute wget with elevated privileges. It allows you to decrease the attack surface.

  • | sudo tee command executes wget with regular privileges and uses elevated privileges only to write data into a selected file.
  • With sudo wget, wget vulnerabilities can be exploited with the elevated privileges.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.