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!

  • youtube-dl -U will do a update
    – Keith5001
    Jun 7, 2021 at 17:28
  • 4
    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. Jun 7, 2021 at 18:06
  • @steeldriver, thanks for the explanation. How should I write it out if I wanted the redirection to have elevated privileges?
    – mysterium
    Jun 22, 2021 at 7:28

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.