从 Bash Shell 下载文件
wget 简介
GNU Wget 是一个用于从 Web 非交互式下载文件的免费实用程序。它支持 HTTP、HTTPS 和 FTP 协议,以及通过 HTTP 代理进行检索。
wget -O newname.txt http://www.het.brown.edu/guide/UNIX-password-security.txt
curl 简介
curl 是一个使用支持的协议(HTTP、HTTPS、FTP、FTPS、TFTP、DICT、TELNET、LDAP 或 FILE)从服务器传输数据或向服务器传输数据的工具。该命令设计为无需用户交互即可工作。
curl -o newname.txt http://www.het.brown.edu/guide/UNIX-password-security.txt
Bash 重定向
`/dev/tcp/HOST/PORT`如果 HOST 是有效的主机名或 Internet 地址,并且 PORT 是整数端口号或服务名称,Bash 会尝试打开到相应套接字的 TCP 连接。
_get (){IFS=/ read proto z host query <<< "$1"exec 3< /dev/tcp/$host/80{echo GET /$query HTTP/1.1echo connection: closeecho host: $hostecho} >&3sed '1,/^$/d' <&3 > $(basename $1)}
# 使用示例
[me@linux ~]$ _get http://www.het.brown.edu/guide/UNIX-password-security.txt[me@linux ~]$ lsUNIX-password-security.txt[me@linux ~]$ type _get_get is a function_get (){IFS=/ read proto z host query <<< "$1";exec 3< /dev/tcp/$host/80;{echo GET /$query HTTP/1.1;echo connection: close;echo host: $host;echo} 1>&3;sed '1,/^$/d' 0<&3 > $(basename $1)}
夜雨聆风