macos OS X:相当于 Linux 的 wget
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4572153/
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
OS X: equivalent of Linux's wget
提问by SyntaxT3rr0r
How can I do an HTTP GET from a Un*x shell script on a stock OS X system? (installing third-party software is not an option, for this has to run on a lot of different systems which I don't have control on).
如何从股票 OS X 系统上的 Un*x shell 脚本执行 HTTP GET?(安装第三方软件不是一种选择,因为这必须在许多我无法控制的不同系统上运行)。
For example if I start the Mercurial server locally doing a hg serve:
例如,如果我在本地启动 Mercurial 服务器执行hg serve:
... $ hg serve
And then, from a Linux that has the wgetcommand I do a wget:
然后,从具有wget命令的 Linux执行 wget:
... $ wget http://127.0.0.1:8000
--2010-12-31 22:18:25-- http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... 200 Script output follows
Length: unspecified [text/html]
Saving to: `index.html
And on the terminal in which I launched the "hg serve"command, I can indeed see that an HTTP GET made its way:
在我启动“hg serve”命令的终端上,我确实可以看到 HTTP GET 成功了:
127.0.0.1 - - [30/Dec/2010 22:18:17] "GET / HTTP/1.0" 200 -
So on Linux one way to do an HTTP GET from a shell script is to use wget(if that command is installed of course).
因此,在 Linux 上,从 shell 脚本执行 HTTP GET 的一种方法是使用wget(当然,如果安装了该命令)。
What other ways are there to do the equivalent of a wget? I'm looking, in particular, for something that would work on stock OS X installs.
还有哪些其他方法可以等效于wget?我特别在寻找可以在 OS X 安装上运行的东西。
回答by SiegeX
I'm going to have to say curl http://127.0.0.1:8000 -o outfile
我将不得不说 curl http://127.0.0.1:8000 -o outfile
回答by Eric Hartford
brew install wget
brew install wget
Homebrewis a package manager for OSX analogous to yum, apt-get, choco, emerge, etc. Be aware that you will also need to install Xcode and the Command Line Tools. Virtually anyone who uses the command line in OSX will want to install these things anyway.
Homebrew是 OSX 的包管理器,类似于 yum、apt-get、choco、emerge 等。请注意,您还需要安装 Xcode 和命令行工具。实际上,任何在 OSX 中使用命令行的人都希望安装这些东西。
If you can't or don't want to use homebrew, you could also:
如果您不能或不想使用自制软件,您还可以:
Install wget manually:
手动安装 wget:
curl -# "http://ftp.gnu.org/gnu/wget/wget-1.17.1.tar.xz" -o "wget.tar.xz"
tar xf wget.tar.xz
cd wget-1.17.1
./configure --with-ssl=openssl -with-libssl-prefix=/usr/local/ssl && make -j8 && make install
Or, use a bash alias:
或者,使用 bash 别名:
function _wget() { curl "" -o $(basename "") ; };
alias wget='_wget'
回答by Ed Henderson
Curl has a mode that is almost equivalent to the default wget.
Curl 的模式几乎等同于默认的 wget。
curl -O <url>
This works just like
这就像
wget <url>
And, if you like, you can add this to your .bashrc:
而且,如果您愿意,可以将其添加到您的 .bashrc 中:
alias wget='curl -O'
It's not 100% compatible, but it works for the most common wget usage (IMO)
它不是 100% 兼容的,但它适用于最常见的 wget 用法(IMO)
回答by Eamon Straughn
1) on your mac type
1) 在你的 mac 类型上
nano /usr/bin/wget
2) paste the following in
2)粘贴以下内容
#!/bin/bash
curl -L -o
3) close then make it executable
3)关闭然后使其可执行
chmod 777 /usr/bin/wget
That's it.
而已。
回答by ismail
Use curl
;
使用curl
;
curl http://127.0.0.1:8000 -o index.html
回答by Oliver Schafeld
Here's the Mac OS X equivalent of Linux's wget.
这是与 Linux 的 wget 等效的 Mac OS X。
For Linux, for instance Ubuntu on an AWS instance, use:
对于 Linux,例如 AWS 实例上的 Ubuntu,请使用:
wget http://example.com/textfile.txt
On a Mac, i.e. for local development, use this:
在 Mac 上,即本地开发,使用这个:
curl http://example.com/textfile.txt -o textfile.txt
The -o parameter is required on a Mac for output into a file instead of on screen. Specify a different target name for renaming the downloaded file.
Mac 上需要 -o 参数才能输出到文件而不是屏幕上。指定不同的目标名称以重命名下载的文件。
Use capital-O for renaming with wget. Lowercase -o will specify output file for transfer log.
使用大写-O 重命名 wget。小写 -o 将指定传输日志的输出文件。
回答by Hammad Haleem
You can either build wget on the mac machine or use MacPorts to install it directly.
你可以在mac机器上构建wget,也可以使用MacPorts直接安装。
sudo port install wget
This would work like a charm, also you can update to the latest version as soon as it's available. Port is much more stable than brew, although has a lot less number of formula and ports.
这就像一个魅力,你也可以在它可用时立即更新到最新版本。Port 比 brew 稳定得多,尽管配方和端口的数量要少得多。
You can install MacPorts from https://www.macports.org/install.php
you can download the .pkg
file and install it.
你可以安装 MacPorts,https://www.macports.org/install.php
你可以下载.pkg
文件并安装它。
回答by Jaya Konduru
Instead of going with equivalent, you can try "brew install wget" and use wget.
您可以尝试“brew install wget”并使用 wget,而不是使用等效的方法。
You need to have brew installed in your mac.
您需要在 Mac 中安装 brew。
回答by James Sumners
You could use curl
instead. It is installed by default into /usr/bin
.
你可以用curl
。它默认安装到/usr/bin
.
回答by Beejor
wget Precompiled Mac Binary
wget 预编译的 Mac 二进制文件
For those looking for a quick wget install on Mac, check out Quentin Stafford-Fraser's precompiled binary here, which has been around for over a decade:
对于那些希望在 Mac 上快速安装 wget 的人,请在此处查看 Quentin Stafford-Fraser 的预编译二进制文件,它已经存在了十多年:
https://statusq.org/archives/2008/07/30/1954/
MD5 for 2008 wget.zip: 24a35d499704eecedd09e0dd52175582
MD5 for 2005 wget.zip: c7b48ec3ff929d9bd28ddb87e1a76ffb
https://statusq.org/archives/2008/07/30/1954/
2008 年的 MD5 wget.zip:24a35d499704eecedd09e0dd52175582
2005 年的 MD5 wget.zip:c7b48ec3ff928db7db9d6
No make/install/port/brew/curl junk. Just download, install, and run. Works with Mac OS X 10.3-10.12+.
没有 make/install/port/brew/curl 垃圾。只需下载、安装和运行。适用于 Mac OS X 10.3-10.12+。