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?


Take a look at the man page for wget.

-O 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.

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

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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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