wget - Cheatsheet

By xngo on July 11, 2019

# Save as output_filename.html. Or overwrite.
    wget http://www.google.com -O output_filename.html
 
# Check for internet connection.
    if wget -q --spider "http://google.com"; then
        echo "Success, got internet connection!"
    else
        echo "Error: No internet connection!"
    fi    
 
# Redirect output to standard output.
    if wget -q "${url}" -O-| grep -qF 'File Not Found'; then
        echo "NO: ${url}"
    else
        echo "YES: ${url}"
    fi
 
# Wget exit code.
    0: No problems occurred.
    1: Generic error code.
    2: Parse error—for instance, when parsing command-line options, the ‘.wgetrc’ or ‘.netrc’...
    3: File I/O error.
    4: Network failure.
    5: SSL verification failure.
    6: Username/password authentication failure.
    7: Protocol errors.
    8: Server issued an error response.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.