有没有一种通过命令行运行的程序可以计算远程文件的校验和?例如获取https://stackoverflow.com/opensearch.xml的校验和。
我想要能够获取新的rss / xml条目可用时的更新。我在考虑每隔一段时间对文件进行校验和,如果不同则必须有更新。我正在寻找编写检查新的rss / xml数据的Shell脚本。
有没有一种通过命令行运行的程序可以计算远程文件的校验和?例如获取https://stackoverflow.com/opensearch.xml的校验和。
我想要能够获取新的rss / xml条目可用时的更新。我在考虑每隔一段时间对文件进行校验和,如果不同则必须有更新。我正在寻找编写检查新的rss / xml数据的Shell脚本。
使用curl快速完成此操作的方法是将输出管道传递给sha1sum,如下所示:
curl -s http://stackoverflow.com/opensearch.xml|sha1sum
curl有一个“-z”选项:
-z/--time-cond <date expression>|<file>
(HTTP/FTP) Request a file that has been modified later
than the given time and date, or one that has been modified before
that time. The <date expression> can be all sorts of date strings
or if it doesn't match any internal ones, it is taken as a filename
and tries to get the modification date (mtime) from <file> instead.
See the curl_getdate(3) man pages for date expression details.
所以你可以做的是:
$ curl http://stackoverflow.com/opensearch.xml -z opensearch.xml -o opensearch.xml
如果远程文件比本地文件更新(本地文件可能不存在 - 这种情况下将下载),则会进行实际下载。这似乎正是您需要的...
wget还有一个选项可以跟踪时间戳 - -N
When running Wget with -N, with or without -r or -p, the decision as to whether
or not to download a newer copy of a file depends on the local and remote
timestamp and size of the file.
-N, --timestamping Turn on time-stamping.
如果使用wget,可以使用以下命令:
$ wget -N http://stackoverflow.com/opensearch.xml
你可以在bash下尝试这个命令:
wget <http://your file link>
md5sum <your file name>
你应该首先检查HTTP头以查看服务器是否愿意告诉你文件的来源;如果不需要,获取整个文件被认为是不好的做法。
否则,你将需要使用类似wget或curl的工具来获取文件,所以我真的希望你不打算处理任何大文件。
-L
选项...curl -sL URL | sha256sum
(macOS) 或者curl -sL URL | shasum -a 256
... - vigocurl -sL
是静默并且跟随重定向。在 Mac 上,我用gsha256sum
替换sha256sum
。 - Pro Backup