Examples of the wget command

 
# Basic examples
wget -O /dev/null -o /dev/null https://www.example.com/test.php

wget -O /test-folder/test.html --no-check-certificate https://www.example.com/test.html

wget --output-document=/test-folder/test.html https://www.example.com/test.html


# Save downloaded file, and the output of the wget command (useful for cron jobs)
wget -O /test-folder/test.txt --no-check-certificate https://www.example.com/test.php > /output-folder/output.txt

# Save downloaded file, and append the output of the wget command to a text file (useful for cron jobs)
wget -O - -a /output-folder/output.txt --no-check-certificate https://www.example.com/test.php >> /test-folder/test.txt


# Specify user agent
wget --user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" https://www.example.com/test.html

wget -O test.html --user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" https://www.example.com/test.html

wget -O test.html --no-check-certificate --user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" https://www.example.com/test.html


# Show request headers being sent 
wget -d https://www.example.com/test.html

# Sending headers
wget -d --header="User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" \
  --header="Referer: http://linuxsecrets.com/" \
  --header="Accept-Encoding: compress, gzip" \
  https://www.example.com/test.html

# Sending referer, user-agent, and headers
wget --referer="http://www.google.com" --user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" \
  --header="Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" \
  --header="Accept-Language: en-us,en;q=0.5" \
  --header="Accept-Encoding: gzip,deflate" \
  --header="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" \
  --header="Keep-Alive: 300" "$@" \
  https://www.example.com/test.html


# Resume downloading  
wget -c https://www.example.com/test.html

wget --continue https://www.example.com/test.html

 

Related Snippets

•  Examples of the curl command
•  Examples of the zip command
•  Examples of touch command
•  Rename a batch of files
•  Delete a batch of files using a regular expression with the find command