Linux 命令行网络相关(curl/wget/nc...)
有待整理。。。
fuser
view which program is using which port.
fuser XXX/tcp # see which program is using tcp port XXX
fuser XXX/upd # see which program is using udp port XXX
fuser -k XXX/tcp # kill the program, if you have right permissions
curl
wget 功能很有限,httpie 虽然比较人性化但是有很多 bug,还是 curl 比较好用。
curl -L/--follow http://example.com follow redirect
curl -I/--head http://example.com only headers
curl -o/--output file http://example.com http -d
curl -v/--verbose http://example.com
curl --data "key=value" http://example.com
curl --data-urlencode "key=
curl -X/--request GET/POST http://example.com
curl -H/--header "Accept: utf-8"
curl --referer http://x.com http://example.com
curl --user-agent
curl --cookie
使用代理
curl -x
cookies
curl -v --cookie "USER_TOKEN=Yes" http://127.0.0.1:5000/
-
According to the man page, for option -b, --cookie, e.g. curl -b
, if the argument is a string having the '=' symbol, it's passed as is, otherwise it's treated as a filename to read cookie from. – ryenus Oct 21 '14 at 2:10 -
multiple cookies can be set with semicolons --cookie "key1=val1;key2=val2;..."
查看网络情况
需要注意的是,在 Linux 上 netstat 已经废弃了,应该使用新的 ss 命令。不过在 macOS 等Unix系统中,还是只有netstat
netstat -a list all ports
netstat -at list all tcp ports
netstat -l all listening ports
netstat -in 查看提供网络接口的信息
netstat -rn 显示路由表
ifconfig eth0 显示接口的状态
ifconfig -a 所有接口的状态
ip addr eth0 全新的命令
Mac
和 Linux 基本相同, 但是缺少 ip 指令, 需要安装 iproute2mac 包
traceroute
nslookup
host
wget --noproxy
mtr
bt download
sudo add-apt-repository ppa:t-tujikawa/ppa sudo apt-get update sudo apt-get install aria2
使用 rsync 同步
rsync -azP local_dir remote_dir
-a
archive,表示归档-n
dry-run,只显示要执行的操作而不具体执行-z
compress,压缩-P
--progress + --partial,显示进度同时断点续传--exclude=<dir>
exclude directory from being rsynced
默认情况下,rsync 使用增量同步,而不会删除文件。使用 --delete
删除文件