这篇文章上次修改于 764 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

1. tcpdump

# 在一个终端监听主机 159.75.86.199 发送或接收到的 icmp 包
# n: Do not convert addresses (host addresses, port numbers, etc.) to names.
# v: (Slightly more) verbose output. For example, the time to live (TTL) and type of service (ToS) information in an IP packet are printed.
# e: Print the link-level header on each dump line.
tcpdump -i en0 -nve icmp and host 159.75.86.199  

# 在另一个终端执行
ping 159.75.86.199  

2. 删除所有监听 80 端口的进程

lsof -i:80 | awk 'NR>1{print $2}' | xargs kill

3. Linux 后台运行命令 nohup

详见:Linux后台运行命令 nohup command > myout.file 2>&1

nohup /bin/bash run.sh delete_ipv6_security_group_rules.py db 100 200 > /data/delete_ipv6.log  2>&1 &

4. tmux


# 查看所有会话
tmux ls

# 会话重命名
ctrl + b + $ 

# 关闭会话
tmux kill-session -t 会话编号

# 窗口重命名
ctrl + b + ,

# 关闭当前窗格
ctrl + b + x

# 禁止窗格重命名:
vim ~/.tmux.conf

输入:
tmux set -wg allow-rename off           
tmux set -wg automatic-rename off

source ~/.tmux.conf

5. 脚本编写:可选参数

#!/bin/bash

array=()

TEMP=`getopt -o w: --long with-module: -- "$@"`

eval set -- "$TEMP"

while true
do
        case "$1" in
                -w|--with-module) array+=($2); shift 2 ;;
                --) shift; break ;;
                *) echo "internal error"; exit 1 ;;
        esac
done

for(( i=0; i<${#array[@]}; i++))
do
        echo ${array[i]};
done;

结果

./test.sh -w a -w b -w c
a
b
c

6. 修改 MySql 密码

# 改密码
password=你的数据库密码
cd $mariadbInstallDir/bin
./mysqladmin -u root password $password
./mysqladmin shutdown -u root -p$password

# 连接 MySql
mysql -u root -p密码

7. 查看 systemd 日志

journalctl -xe -u your_service.service -f