#!/bin/bash #mac 用户目录,linux改成 home for user in `ls /Users` do #zsh 的命令历史存放文件 file="/Users/"$user"/.zsh_history" if [ -e $file ]; then for a in `grep $1 $file` do echo $user" "$a done fi done
把上述代码保存到 myhistory中,然后
chmod +x myhistory
要查看谁执行过 ls 命令:
./myhistory ls