Wget in Crontab: Disable Saving File

Last updated on Jan 2, 2020 in Linux

When the cron job executes wget command (fetches URL resource), it creates a new file every time. It doesn’t overwrite the old downloaded file, but appends a number so by time, there will be thousands of files unless you tweak your crontab to suppress the output.

Open Crontab

Open the crontab in your favorite text editor:

$ vim /etc/crontab

Redirect Output to /dev/null Instead of a File

Add /dev/null at the end of the line to enable redirection of the wget’s output:

* * * * * wget https://fullstack-tutorials.com/resource >/dev/null 2>&1
  • >/dev/null tells the cron to send output (STDOUT) to /dev/null, which destroys the useless data
  • 2>&1 tells the cron to send errors (STDERR) to the same target than the normal output (STDOUT)

After this operation, no more downloaded files are created. Please note that also errors are suppressed, so in case of error, there is no track of it.