Skip to content

/flags/wget/wget-n-timestamping

wget -N (--timestamping): download only if the remote file is newer

The commands on this page have not been executed by our verification runner yet.updated
tool
wget
command
wget
flag
-N, --timestamping
default
off (an existing file is kept and the new download is saved as FILE.1)

wget -N https://example.org/app.tar.gz downloads the file only if there is no local copy, if the server's copy is newer (according to its Last-Modified header) or if the sizes differ. Otherwise wget prints that the server file is no newer and exits without transferring the body. After a download, wget sets the local file's modification time to the server's Last-Modified date, which is what makes the comparison work on the next run. --mirror (-m) turns -N on for you.

How the comparison works

SituationWhat wget -N does
No local fileDownloads it
Server copy newer than local mtimeDownloads and overwrites the local file (no FILE.1)
Same date or older, same sizeSkips it
Same date or older, different sizeDownloads it again
No Last-Modified headerDownloads it; timestamping is turned off for that file
HTTP 304 to the conditional requestSkips it without receiving the body

By default wget sends the local file's date in an If-Modified-Since header, so an unchanged file costs one short 304 Not Modified response. --no-if-modified-since makes wget send a HEAD request first and compare the headers itself, which helps with servers that ignore or mishandle conditional requests.

Messages you will see

Printed in verbose mode (the default; -q hides them). These strings come from wget's source code:

text
File ‘app.tar.gz’ not modified on server. Omitting download.
Server file no newer than local file ‘app.tar.gz’ -- not retrieving.
Remote file is newer, retrieving.
The sizes do not match (local 1048576) -- retrieving.
Last-modified header missing -- time-stamps turned off.

The first line answers a 304; the others come from the HEAD-based comparison.

Examples

bash
wget -N https://example.org/data/prices.csv                # refresh a single file
wget -N -P cache/ -i urls.txt                              # refresh a list into cache/
wget -r -np -N https://example.org/files/                  # update a recursive copy
wget -N --no-if-modified-since https://example.org/app.tar.gz

Options that conflict with -N

OptionInteraction
-O FILETimestamping is disabled with a warning: the local name no longer matches the remote file
-nc, --no-clobberRejected: wget prints Can't timestamp and not clobber old files at the same time.
-c, --continueWorks, but a newer server file is fetched in full, not resumed
--no-use-server-timestampsKeeps the download time as mtime, so later -N runs compare against it
-S, --server-responseShows the Last-Modified header wget is comparing

With -O wget prints WARNING: timestamping does nothing in combination with -O. See the manual for details. and downloads every time. Use -P DIR (see wget -P) when you only need a different directory, and keep the file name from the URL.

FAQ

Why does wget -N download the file every time?

Either the server sends no Last-Modified header (wget then says time-stamps are turned off), the sizes differ, or -O is also set, which disables timestamping. Run with -S to see the response headers.

What is the difference between -N and -nc?

-nc never downloads a file that already exists locally, whatever changed on the server. -N downloads it again when the server copy is newer or a different size. The two cannot be combined.

Can I use -N without the local file getting the server's date?

No, the comparison depends on it. --no-use-server-timestamps keeps the local download time, which makes the next -N run compare against that time instead of the server's date.

Sources