Marcus Junius Brutus
Marcus Junius Brutus

Reputation: 27286

wget :: rename downloaded files and only download if newer

I am trying to use wget to download a file under a different local name and only download if the file on the server is newer.

What I thought I could do was use the -O option of wget so as to be able to choose the name of the downloaded file, as in:

wget http://example.com/weird-name -O local-name

and combine that with the -N option that doesn't download anything except if the timestamp is newer on the server. For reasons explained in the comments below, wget refuses to combine both flags:

WARNING: timestamping does nothing in combination with -O. See the manual
for details.

Any ideas on succinct work-arounds ?

Upvotes: 7

Views: 2934

Answers (3)

Francesco Frassinelli
Francesco Frassinelli

Reputation: 3375

You can use curl as an alternative:

curl example.com/weird-name -o local-name -z local-name

Related: https://superuser.com/a/908523

Upvotes: 0

Mark Stosberg
Mark Stosberg

Reputation: 13411

If using other tool is possible in your case, I recommend the free, open source lwp-mirror:

lwp-mirror [-options] <url> <file>

It works just as you wish, with no workarounds.

This command is provided by the libwww-perl package on Ubuntu and Debian among other places.

Note that lwp-mirror doesn't support all of wget's other features. For example, it doesn't allow you to set a User Agent for the request like wget does.

Upvotes: 2

Zombo
Zombo

Reputation: 1

Download it, then create a link

wget -N example.com/weird-name
ln weird-name local-name

After that you can run wget -N and it will work as expected:

  • Only download if newer
  • If a new file is downloaded it will be accessible from either name, without costing you extra drive space

Upvotes: 2

Related Questions