Linux 如何请求文件但不使用 Wget 保存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9691367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:09:12  来源:igfitidea点击:

How do I request a file but not save it with Wget?

linuxcachingwget

提问by T. Brian Jones

I'm using Wget to make http requests to a fresh web server. I am doing this to warm the MySQL cache. I do not want to save the files after they are served.

我正在使用 Wget 向新的 Web 服务器发出 http 请求。我这样做是为了预热 MySQL 缓存。我不想在提供文件后保存文件。

wget -nv -do-not-save-file $url

Can I do something like -do-not-save-filewith wget?

我可以-do-not-save-file用 wget做类似的事情吗?

采纳答案by perreal

Use qflag for quiet mode, and tell wgetto output to stdout with O-(uppercase o) and redirect to /dev/nullto discard the output:

使用q安静模式的标志,并告诉wget输出到标准输出O-(大写 o)并重定向/dev/null到丢弃输出:

wget -qO- $url &> /dev/null

wget -qO- $url &> /dev/null

>redirects application output (to a file). if >is preceded by ampersand, shell redirects all outputs (error and normal) to the file right of >. If you don't specify ampersand, then only normal output is redirected.

>将应用程序输出重定向(到文件)。如果>前面有 & 符号,shell 会将所有输出(错误和正常)重定向到>. 如果不指定&符号,则仅重定向正常输出。

./app &>  file # redirect error and standard output to file
./app >   file # redirect standard output to file
./app 2>  file # redirect error output to file

if file is /dev/nullthen all is discarded.

如果文件是/dev/null那么所有都被丢弃。

This works as well, and simpler:

这也有效,而且更简单:

wget -O/dev/null -q $url

回答by Oleg Mikheev

Curldoes that by default without any parameters or flags, I would use it for your purposes:

默认情况下,Curl在没有任何参数或标志的情况下执行此操作,我会将它用于您的目的:

curl $url > /dev/null 2>&1

Curl is more about streams and wget is more about copying sites based on this comparison.

Curl 更侧重于流,而 wget 更侧重于基于这种比较复制站点。

回答by Marco Biscaro

You can use -O-(uppercase o) to redirect content to the stdout (standard output) or to a file (even special files like /dev/null/dev/stderr/dev/stdout)

您可以使用-O-(大写 o)将内容重定向到 stdout(标准输出)或文件(甚至是像 一样的特殊文件/dev/null/dev/stderr/dev/stdout

wget -O- http://yourdomain.com

Or:

或者:

wget -O- http://yourdomain.com > /dev/null

Or: (same result as last command)

或者:(与上一条命令的结果相同)

wget -O/dev/null http://yourdomain.com