What does "wget -O" mean?
Asked Answered
C

5

71

I have an wget command like this in my shell script:

reponse="`wget -O- http:localhost:8080/app/index.html`"

I don't understand the -O- option. I was explained that -O is output to somewhere and - is output to the current stream. I don't see any explaination of "-" in wget. Is that a standard thing for shell scripting. Where I can find reference to it?

Thanks,

Connolly answered 22/3, 2012 at 20:46 Comment(0)
Q
109

Here's the man page of wget -O:

http://www.gnu.org/software/wget/manual/html_node/Download-Options.html#Download-Options

Here's a few examples:

  1. wget with no flag

    wget www.stackoverflow.com
    

    Output:

    A file named as index.html

  2. wget with -O flag

    wget -O filename.html www.stackoverflow.com
    

    Output:

    A file named as filename.html

  3. wget with -O- flag

    wget -O- www.stackoverflow.com
    

    Output:

    Output to stdout

Quantifier answered 27/5, 2013 at 2:0 Comment(0)
P
12

for the manual of wget: use man wget if you are on Unix platform. Else, try "man page wget" on google.

The -O- stand for "Get as a file and print the result on STDOUT"

Phares answered 22/3, 2012 at 20:52 Comment(2)
I can't find "Get as a file and print the result on STDOUT" in "man wget". I am using Ubuntu.Connolly
-O allow you to save result in file. The "-" is pipe redirection to STDOUT on linux. Therefore: "Get as a file and print the result on STDOUT"Phares
E
5

Here is the syntax:

wget -O (filename|-) [url]

If you write a "filename" the output will be saved into a file named "filename".

If you put "-" instead of "filename". the output of the code will be represented in stdout.

Enschede answered 16/2, 2022 at 9:37 Comment(0)
H
1

Depending on your system you should be able to find reference by typing man wget. The GNU Wget man page says this of the -O|--output-document flag:

If - is used as file, documents will be printed to standard output, disabling link conversion. (Use ./- to print to a file literally named -.)

And continues…

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.

It's not uncommon to see combined with -q and written as -q0- or -q0 - followed by a uri. It validates against the POSIX standard so, yeah, I'd say it's a standard thing for shell scripting.

Holguin answered 31/7, 2018 at 3:3 Comment(0)
R
1
wget -O teleComData.csv https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/teleCust1000t.csv

This command downloads the csv file from the specified url and saves it as teleComData.csv. If you hadn't used the -O flag, it would simply save the file as it is.

Recreation answered 18/4, 2020 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.