168

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?

4
  • 3
    This is a better question for Super User or Unix.SE.
    – Matt Ball
    Mar 13, 2012 at 20:19
  • 6
    as a developer I want to test a server with wget and than this question is seriously on-topic. As on-topic best answer got 142 positive votes, so this question should be reenabled as on-topic Sep 30, 2016 at 17:43
  • Alternatively to -q and -O, use the flags -nd (no directory) and --delete-after.
    – Suzana
    Sep 25, 2018 at 9:36
  • 2
    According to the help doc(wget -h), you can use --spider option to skip download(version 1.14).
    – rocky qi
    May 9, 2019 at 4:34

3 Answers 3

292

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
11
  • what do the ampersand and greater than do in this command? can you just pipe the output to /dev/null ... wget -qO- | /dev/null ... ? Mar 13, 2012 at 20:22
  • Uh, I tried this and it didn't work for me. From what I found out, the ampersand should come after the greater than symbol. Jul 12, 2013 at 10:32
  • 7
    For Windows users: wget -q -O NUL http://... Turns off logging and routes download to NUL (same as /dev/null)
    – vidario
    Nov 7, 2013 at 11:49
  • 3
    wget --spider $url Will do it. May 26, 2014 at 0:48
  • 1
    wget -O/dev/null $url
    – Storm
    Sep 16, 2015 at 8:58
55

You can use -O- (uppercase o) to redirect content to the stdout (standard output) or to a file (even special files like /dev/null /dev/stderr /dev/stdout )

wget -O- http://yourdomain.com

Or:

wget -O- http://yourdomain.com > /dev/null

Or: (same result as last command)

wget -O/dev/null http://yourdomain.com
2
  • Thx, works on windows as well.
    – Pyjong
    Aug 29, 2013 at 7:36
  • Thanks, the direct-to-/dev/null was smart, and thus the correct answer: I want the "stats output", but not the contents.
    – stolsvik
    Dec 21, 2016 at 15:26
45

Curl does that by default without any parameters or flags, I would use it for your purposes:

curl $url > /dev/null 2>&1

Curl is more about streams and wget is more about copying sites based on this comparison.

4
  • 1
    Cold you explain what 2>&1 means? I get > but why the end?
    – apscience
    Sep 7, 2013 at 11:01
  • 2
    @gladoscc first >/dev/null redirects std out to /dev/null (>/dev/null is short for 1>/dev/null), the second redirects std err to std out. Sep 9, 2013 at 22:33
  • 1
    @apscience Just to add. The file descriptor for std out is 1. Shells assume std out when you leave off the descriptor from a redirect. So >foo is interpreted as 1>foo. When & follows a redirect, it instructs the shell to redirect the former file descriptor to the same output as the later. In this case, 2>&1 says redirect file descriptor 2 (std err) to the same place as file descriptor 1 (std out). Since std out is already redirected to /dev/null, std err will also be redirected there. You could also write: 1>/dev/null 2>/dev/null or 2>/dev/null >&2.
    – ktbiz
    Mar 1, 2017 at 4:27
  • This answer is correct, but then includes the same output redirection as the chosen answer. Simply running curl http://www.example.com is sufficient. Jul 11, 2017 at 21:23

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