备份
复制文件保留目录路径
cp -a --parent -t . /etc/ufw/user*.rules
rsync用root身份复制特殊权限文件(远程机器不允许root登录)
rsync -avPh --rsync-path="sudo rsync" -e "ssh -i /home/ubuntu/.ssh/id_rsa" /etc/nginx.conf [email protected]:/etc/
网络
shell取ping某个网站的时间的整数(用于比较)
$ ping google.com
PING google.com(kix06s10-in-x0e.1e100.net (2404:6800:400a:804::200e)) 56 data bytes
64 bytes from kix06s10-in-x0e.1e100.net (2404:6800:400a:804::200e): icmp_seq=1 ttl=120 time=8.15 ms
$ ping -c 1 google.com | sed -ne '/.*time=/{;s///;s/\..*//;p;}'
8
系统管理
查看进程树
$ pstree -lpsH $PPID
systemd(1)─┬─agetty(1840)
├─cron(1816)
├─dbus-daemon(1158)
├─irqbalance(1181)───{irqbalance}(1235)
├─multipathd(659)─┬─{multipathd}(663)
│ ├─{multipathd}(664)
# -l 不截断过长行 -p显示进程id -H高亮显示当前进程
寻找占空间最大的目录
$ du -d1|sort -nr
29111196 .
18242712 ./rustsrc
8438500 ./padavan-ng
1096212 ./rust
345184 ./.cargo
342200 ./lib
$ du -hd1
7.8M ./speed
20K ./ca
8.0K ./.vim
194M ./go
28K ./.config
335M ./lib
8.1G ./padavan-ng