systemd查看当前所有正在运行中的服务
systemctl list-units --type=service --state=running
按启动时间排序查看所有进程
ps aux --sort=start_time
查看当前谁在进行系统调用
需要安装 bpftrace ,安装好后执行:
bpftrace -e ' tracepoint:syscalls:sys_enter_execve { printf("comm: %s, argv[0]:%s, argv[1]:%s, arg[2]: %s, arg[3]: %s, pid: %d, cpu: %d\n", comm, str(args->argv[0]),str(args->argv[1]), str(args->argv[2]), str(args->argv[3]), pid, cpu); }'

图中看到,mgw-high-ava 这个进程调用了ping 192.168.4.8 -I eno1 命令。
find怎么排除指定目录
排除一个目录用 -not -path “xxx” 或 ! -path “xxx” 。如果要想排除多个目录
find . -type f -name ".txt" -not -path "./example/*"
# 或者
find . -type f -name "*.txt" ! -path "./example/*"
如果要想排除多个目录,要用 -a 连结起来。
find . -type f -size +10M -not -path "./mirror/*" -a ! -path "*wp-data*"
Bash中实现字符串大小写转换
使用Bash参数扩展方案,转大写:
echo "${str^^}"
转小写:
echo "${str,,}"
查看系统当中已被删除但未释放的文件
使用lsof命令,+L1,表示列出系统中所有 链接数小于1 的已打开文件,链接数为0表示文件已被删除(unlinked),但仍被某些进程占用(例如日志文件被删除但未释放)。
lsof +L1
查看iptable是否是nftable兼容版本
使用iptables –version 命令。
[root@znl.pub ~]# iptables --version
iptables v1.8.4 (nf_tables)
监控 Linux 下 /tmp 目录中创建 pymp-*
目录的进程
使用 auditd 审计系统。centos 8上面默认自带。
# 1. 查看auditd 服务是否已经运行 没有运行的话,我们启动它
systemctl status auditd
systemctl start auditd
# 2. 添加审计规则(监控/tmp下pymp-开头的目录创建)
auditctl -w /tmp -p wxa -k tmp_pymp_dir_creation
# 3. 查看审计日志
ausearch -k pymp_dir_creation | less
# 4. 在less中,执行查找 pymp-
:/pymp-
# 以 ---- 为分割的一块区域为一个完整的审计事件,为了方便我们分析
# 5. 删除我们添加的auditd规则
# 首先列出规则
auditctl -l
# 找到要删除的规则,就拿我们上面使用的规则为例
-w /tmp -p wxa -k tmp_pymp_dir_creation
# 方法1:使用 -W 删除规则,将原规则复制粘贴并修改小w为大W。
# 针对文件/目录监视规则(-w 添加的),必须使用完全相同的参数删除
auditctl -W /tmp -p wxa -k tmp_pymp_dir_creation
# 方法2:清空所有规则,参数为 -D
auditctl -D

