1

There is a .tgz archive on a remote server. I only want to download this file if it is more recent than the local copy of its contents that I have. If I kept the old copy of the .tgz around, I could use wget -N. But instead, I only keep the extracted contents. How can I use the equivalent of wget -N while keeping only a copy of the contents? The solution should be as cross-platform as possible.

One thing I tried was:

  • storing the extracted content in a unique directory
  • setting access/modified timestamps on the directory to be the same as that of the tarball
  • when checking for a new version, touch -r <directory> <tarball> to create a fake version of the target file with the appropriate timestamps
  • wget -N

But this failed because wget -N checks both the file size and the timestamps, and my fake tarball doesn't have the right size.

2 Answers 2

0

Is there a reason you don’t want to keep the old tarball? That’s really the easiest and most foolproof method.

On Linux, you could use dd to create a file of the right size pretty easily and use touch to fix the time stamp.


Save the time stamp and size before you delete the tarball:

wc -c tar.tgz | awk ‘{ print $1 }’ > ref_file
touch -r tar.tgz ref_file

Recreate dummy of right size:

dd of=tar.tgz seek=$(cat ref_file) count=0
touch -r ref_file tar.tgz
0

Can you try with curl instead of wget?

$ curl --time-cond <directory> --remote-time --output <tarball> <download_url>

--time-cond can be either a time string or a filename.

--remote-time sets the time of the downloaded file to the same as the remote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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