一、Linux中的~/.bash_history文件说明:
该文件保存了linux系统中运行过的命令的历史。使用该文件来获取命令的列表,并统计命令的执行次数。统计时,只统计命令的名称,以不同参数调用相同的命令也视为同一命令。
二、示例代码:
import os
from collections import Counter
counter = Counter()
with open(os.path.expanduser('~/.bash_history')) as file:
    for line in file:
        cmd = line.strip().split()
        if cmd:
            counter[cmd[0]] += 1
    print(counter.most_common(10)) 
该示例统计每条命令的出现次数,并找出出现次数最多的十条命令。
三、运行结果:



















