How do I request a file but not save it with Wget?

T. Brian Jones picture T. Brian Jones · Mar 13, 2012 · Viewed 135.2k times · Source

I'm using Wget to make http requests to a fresh web server. I am doing this to warm the MySQL cache. I do not want to save the files after they are served.

wget -nv -do-not-save-file $url

Can I do something like -do-not-save-file with wget?

Answer

perreal picture perreal · Mar 13, 2012

Use q flag for quiet mode, and tell wget to output to stdout with O- (uppercase o) and redirect to /dev/null to discard the output:

wget -qO- $url &> /dev/null

> redirects application output (to a file). if > is preceded by ampersand, shell redirects all outputs (error and normal) to the file right of >. If you don't specify ampersand, then only normal output is redirected.

./app &>  file # redirect error and standard output to file
./app >   file # redirect standard output to file
./app 2>  file # redirect error output to file

if file is /dev/null then all is discarded.

This works as well, and simpler:

wget -O/dev/null -q $url