从Mac OS上的日志文件获取常用命令计数

时间:2018-07-19 13:07:37

标签: macos shell unix

我需要从系统获取有关我已输入“ pw”,“ ls”和“ cd”命令的次数的信息。

#!/bin/bash 
#HISTFILE=~/.bash_history
#set -o history
echo "Printing number of ls commands used" > LogFile
a='history | grep -w "ls" | wc -1'
echo $a >> LogFile
echo "Printing number of cd commands used" >> LogFile
b='history | grep -w "cd" | wc -1'
echo $b >> LogFile
echo "Printing number of pwd commands used" >> LogFile
b='history | grep -w "pwd" | wc -1'
echo $c >> LogFile

cat LogFile

和我在终端上的输出:

Joyces-MacBook-Pro:desktop Joyce$ ./failedlogin_detect.sh
Printing number of ls commands used
history | grep -w "ls" | wc -1
Printing number of cd commands used
history | grep -w "cd" | wc -1
Printing number of pwd commands used

句子打印得很好,但是它没有从系统中检索计数。请给我扔骨头。

0 个答案:

没有答案