wgetを昔から使ってたのですが、環境によってはcurlのみ使えるということがあります。そのたびに毎度ググっているので、備忘として残しておきます。
バージョン
[root@a86bf967f8dd /]# curl -V curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0 [root@a86bf967f8dd /]# wget -V GNU Wget 1.14 built on linux-gnu.
コマンド
標準出力に結果を出力する(curl, wget -O -)
[root@a86bf967f8dd /]# curl http://192.168.0.54:8080/index.html <html> <head>test</head> <body> <h1>Test Page.</h1> </body> </html> [root@a86bf967f8dd /]# wget http://192.168.0.54:8080/index.html -O - --2021-08-12 16:00:52-- http://192.168.0.54:8080/index.html Connecting to 192.168.0.54:8080... connected. HTTP request sent, awaiting response... 200 OK Length: 87 [text/html] Saving to: 'STDOUT' 0% [ ] 0 --.-K/s <html> <head>test</head> <body> <h1>Test Page.</h1> </body> 100%[===================================================================================================>] 87 --.-K/s in 0s 2021-08-12 16:00:52 (3.43 MB/s) - written to stdout [87/87]
ファイルをダウンロードする(ファイル名指定なし)(curl -O, wget)
[root@a86bf967f8dd /]# curl -O http://192.168.0.54:8080/hoge.zip % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 228 100 228 0 0 61306 0 --:--:-- --:--:-- --:--:-- 76000 [root@a86bf967f8dd /]# wget http://192.168.0.54:8080/hoge.zip --2021-08-12 16:10:10-- http://192.168.0.54:8080/hoge.zip Connecting to 192.168.0.54:8080... connected. HTTP request sent, awaiting response... 200 OK Length: 228 [application/zip] Saving to: 'hoge.zip' 100%[===================================================================================================>] 228 --.-K/s in 0s 2021-08-12 16:10:10 (10.2 MB/s) - 'hoge.zip' saved [228/228]
ファイルをダウンロードする(ファイル名指定あり)(curl -o, wget -O)
[root@a86bf967f8dd /]# curl http://192.168.0.54:8080/hoge.zip -o test.zip % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 228 100 228 0 0 61109 0 --:--:-- --:--:-- --:--:-- 76000 [root@a86bf967f8dd /]# wget http://192.168.0.54:8080/hoge.zip -O test2.zip --2021-08-12 16:13:56-- http://192.168.0.54:8080/hoge.zip Connecting to 192.168.0.54:8080... connected. HTTP request sent, awaiting response... 200 OK Length: 228 [application/zip] Saving to: 'test2.zip' 100%[===================================================================================================>] 228 --.-K/s in 0s 2021-08-12 16:13:56 (12.6 MB/s) - 'test2.zip' saved [228/228]