linux-shell-snippets
文章目录
TL;dr
# quietly add a user without password
adduser --quiet --disabled-password --shell /bin/bash --home /home/newuser --gecos "User" newuser
# set password
echo "newuser:newpassword" | chpasswd
nc -w 1 qq.com 80 < /dev/null && echo "tcp port ok"
pstree -c -p -s -S -h -a 17648
[ -f /etc/passwd ] && ( echo "1" ) || :
sudo pipinstall ngxtop
sudo yum install -y libpcap libpcap-devel
sudo yum install -y epel-release
sudo yum install -y nethogs nload
/usr/bin/ncat --listen -4 -vvv --keep-open --wait 50 --sh-exec "cat -n | tee -a ./out.txt" 8080
/usr/bin/ncat --listen -4 --verbose --keep-open --wait 50 --sh-exec "cat -n | tee -a ./out.txt" 9090
/usr/bin/nping -4 --verbose -c 1 -p 9090 localhost
python3 -c "import socket;print([(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])"
ip a |grep <ip> |awk '{print $NF}'
ip r |grep <ip> |cut -d " " -f 3
curl -w "TCP handshake: %{time_connect}, SSL handshake: %{time_appconnect}\n" -so /dev/null https://blog.ziki.cn
journalctl -k --no-pager
systemctl -a --no-pager
systemctl list-unit-files --no-pager
systemd-cgls --no-pager
sysctl -a --ignore |& grep ipv4.ip_forward
sysctl -a --ignore 2>&1 | grep ipv4.ip_forward
sysctl -a --ignore 2>/dev/null | grep rp_filter
sysctl -a --ignore 2>&1 | grep ipv4.ip_
sysctl --all --ignore 2>&1 |wc -l
## shell下循环输出 1-10
# 方法1
for i in {1..10};do echo $i;done
# 方法2
for i in $(seq 1 10);do echo $i;done
# 方法3
for ((i=1;i<=10;i++)); do echo $i;done
## shell下计算 5+6
# 方法1
let a=5;b=6;let c=a+b;echo $c
# 方法2
a=5;b=6;c=$((a+b)); echo $c
## shell下判断 /tmp/f 目录是否存在,如果不存在则创建目录
# 方法1
[ -d /tmp/f ] || { mkdir -p /tmp/f; }
# 方法2
if [ ! -d "/tmp/f" ]; then mkdir /tmp/f; fi
ref
systemctl disable firewalld systemctl stop firewalld systemctl restart docker
上次更新 2021-01-01
原始文档 查看本文 Markdown 版本 »