5

I am trying to install dropbox onto my Debian machine, and I saw the instruction

cd ~ && wget -O - "some website leading to the download of a tar file" | tar xzf - 

But what I did was just typing this:

wget -O - "some website leading to the download of a tar file"

and I got a lot of rubbish on my terminal. What does wget -O - means? Does it do any harm to my computer?

4 Answers 4

10

Take a look at the man page for wget.

-O file
   --output-document=file
       The documents will not be written to the appropriate files, but all
       will be concatenated together and written to file.  If - is used as
       file, documents will be printed to standard output, disabling link
       conversion.  (Use ./- to print to a file literally named -.)

       Use of -O is not intended to mean simply "use the name file instead
       of the one in the URL;" rather, it is analogous to shell redirection:
       wget -O file http://foo is intended to work like 
       wget -O - http://foo > file; file will be truncated immediately, and
       all downloaded content will be written there.

So you can either download the contents of "URL" to a file using -O somefile or you can download it and redirect its contents via STDOUT to another tool to do something with it. In this case that's what they're doing with the | tar xvf -.

Your command:

$ cd ~ && wget -O - "some website leading to the download of a tar file" | tar xzf -

The above is taking the tarball from the "URL" and as it's being downloaded it's being redirected to the command tar so that it can be unpacked into your filesystem.

2
  • I often see in places where one has to download APT repository key the usage wget -O- https://updates.signal.org/desktop/apt/keys.asc | gpg --dearmor > signal-desktop-keyring.gpg. Mind there is no space after the big letter O and the dash is right after it. First it looked strange to me, but it is common behaviour of the Linux parameters. One can put values without delimiting them from the letter of parameter. I did it often when connecting with ssh on non default port (ssh -p6666) or passing user and password to MySQL CLI client (mysql -psecretpassword -uadmin)
    – Marecky
    Mar 21, 2021 at 22:29
  • @slm How the tar commands extract the STDOUT? I mean the output looks like a bunch of strings.
    – ado sar
    Sep 18, 2022 at 17:55
1

wget -O - <url> means that wget will download the url and print the file to STDOUT, hence the garbage in your terminal. The full command pipes that output to tar xzf to extract and (presumably) produce useful files.

0
wget -O | gzip -c > file_name.gz

it mean wget get the data from www regardless their type. and output that file. it is either html or file from ftp.

and gzip will write that file in the compressed form.

for more info read the help

$ man wget  
$ man gzip 
$ wget --help  ( for just option of the wget)
$ gzip --help
1
  • there is not hyphen after. before O it is required for short option. Some people use this just - and url. That is - point to url I think. Nov 20, 2019 at 5:53
-1

Here is the use case to understand wget -O.

to download a single file

wget http://machineintellect.cn/testfile.zip

this command will download a file, and name it testfile.zip, which is after the last /

but, if u use wget directly on an URL like this

wget http://machineintellect.cn/download?id=1

the downloaded file will be named like download.aspx?id=1080, which is not what u want.

so, u can use -O to specify the target local file name, like this

wget -O target-local.zip http://machineintellect.cn/download.aspx?id=1080

this command will give u a file named target-local.zip

1
  • 1
    It doesn't answer the question: What is the meaning of wget -O -
    – GAD3R
    Oct 30, 2019 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .