查看歷史命令:history
查看最近使用過的5條命令: history | tail -5
統計經常使用的命令:history | awk '{print $2}' | sort | uniq -c | sort -nr | head -5
結果第一列次數,第二列是使用的命令
解釋:
-
awk '{print $2}'
從歷史文件中打印第2列字符串,不顯示命令選項和參數 -
sort
按字母順序排列所有行 -
uniq -c
刪除重複行並對它們進行計數統計 -
sort -nr
根據 uniq 命令返回的統計數反向排序
也可以使用正序查看使用命令:history | awk {'print $2'} | sort | uniq -c | sort -n | tail -n5
或將所有使用過的命令導出txt中:history | awk {'print $2'} | sort | uniq -c | sort -n > history.txt