Last active
October 12, 2015 18:57
-
-
Save pschwede/4071846 to your computer and use it in GitHub Desktop.
Unix command history distribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from os.path import expanduser | |
from collections import Counter | |
distribution = Counter() | |
f = open(expanduser("~/.bash_history")) | |
commands = list() | |
for line in f.readlines(): | |
line = line.replace("\n","").split(" ") | |
for i in range(1, len(line) + 1): | |
commands.append(" ".join(line[:i])) | |
f.close() | |
for command in commands: | |
distribution[command] += 1 | |
print "Cnt:\tCmd:" | |
for cmd,cnt in sorted(distribution.items(), key=lambda x: x[1] * len(x[0])): | |
print "%s\t'%s'" % (cnt, cmd) |
In bash:
# weighted sort by command length and count
history | awk '{ print $2 }' | sort | uniq -c | awk '{ print $1+$1+length($2), $1, $2 }' | sort -n | awk '{ print $2, $3 }'
# sort by command count
history | awk '{ print $2 }' | sort | uniq -c | sort -n
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, I made an update!