如何使用 Bash 从 Internet 下载文件到我的 linux 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14300794/
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
How do I download a file from the internet to my linux server with Bash
提问by user1893185
I recently had to upgrade to a VPS server (HostGator Linux) because I wanted to run a script that was a bit more complicated than the regular PHP db manipulation. I'm trying to install a JDK and Apache Ant (if it matters, for compiling Android Apps on server).
我最近不得不升级到 VPS 服务器(HostGator Linux),因为我想运行一个比常规 PHP 数据库操作更复杂的脚本。我正在尝试安装 JDK 和 Apache Ant(如果重要,用于在服务器上编译 Android 应用程序)。
I watched tutorials on Linux Bash and started using it. I am currently trying to install Java (with JDK and JRE) on to the server.
我看了有关 Linux Bash 的教程并开始使用它。我目前正在尝试在服务器上安装 Java(使用 JDK 和 JRE)。
I am following the tutorial on this page: http://www.oracle.com/technetwork/java/javase/install-linux-64-self-extracting-142068.html
我正在关注此页面上的教程:http: //www.oracle.com/technetwork/java/javase/install-linux-64-self-extracting-142068.html
However, I don't know what to do at this line:
但是,我不知道在这一行该怎么做:
Download and check the download file size.
You can download to any directory that you can write to.
下载并检查下载文件大小。
您可以下载到任何可以写入的目录。
How do I download Java from the command line?
如何从命令行下载 Java?
If it matters, I am running CentOS v5.8
如果重要,我正在运行 CentOS v5.8
回答by Alex DiCarlo
You can use the command wget
to download from command line. Specifically, you could use
您可以使用该命令从命令行wget
下载。具体来说,你可以使用
wget http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-x64.tar.gz
However because Oracle requires you to accept a license agreement this may not work (and I am currently unable to test it).
但是,因为 Oracle 要求您接受许可协议,所以这可能不起作用(我目前无法对其进行测试)。
回答by Jens Schauder
I guess you could use curl
and wget
, but since Oracle requires you to check of some checkmarks this will be painfull to emulate with the tools mentioned. You would have to download the page with the license agreement and from looking at it figure out what request is needed to get to the actual download.
我想您可以使用curl
and wget
,但是由于 Oracle 要求您检查一些复选标记,因此使用提到的工具进行模拟会很痛苦。您必须下载带有许可协议的页面,并通过查看它找出需要什么请求才能进行实际下载。
Of course you could simply start a browser, but this might not qualify as 'from the command line'. So you might want to look into lynx
, a text based browser.
当然,您可以简单地启动浏览器,但这可能不符合“从命令行”的要求。因此,您可能想要查看lynx
基于文本的浏览器。
回答by imxylz
Using wget
使用 wget
wget -O /tmp/myfile 'http://www.google.com/logo.jpg'
or curl:
或卷曲:
curl -o /tmp/myfile 'http://www.google.com/logo.jpg'