我如何从网络上区分两个文件

poo*_*Dev 13 unix diff curl pipe command-line-interface

我想看看2个文件的差异,这些文件不在本地文件系统中,而是在Web上.所以,我认为如果必须使用diff,curl和某种管道.

就像是

curl http://to.my/file/one.js http://to.my/file.two.js | diff 
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

fed*_*qui 39

UNIX工具diff可以比较两个文件.如果使用<()表达式,则可以在间接对象中比较命令的输出:

diff <(curl file1) <(curl file2)
Run Code Online (Sandbox Code Playgroud)

所以在你的情况下,你可以说:

diff <(curl -s http://to.my/file/one.js) <(curl -s http://to.my/file.two.js)
Run Code Online (Sandbox Code Playgroud)

  • 不错的一点,我会添加** - s**来使curl保持沉默并仅比较内容,例如:`diff <(curl -s http://to.my/file/one.js)<(curl -s http ://to.my/file.two.js)` (11认同)