Skip to content

Instantly share code, notes, and snippets.

@jessebutryn
Last active Oct 17, 2019
Embed
What would you like to do?
Calculating the character distribution of common unix commands, builtins, and keywords
! 1
: 1
K 1
O 1
{ 1
} 1
7 2
E 2
G 2
H 2
I 2
L 2
T 2
] 2
6 3
B 3
F 3
N 3
W 3
9 4
P 4
[ 4
A 5
D 5
U 6
4 7
C 7
+ 8
M 8
R 9
S 10
3 11
j 13
q 29
z 51
2 58
_ 60
- 77
1 77
8 79
w 80
5 81
v 85
x 94
y 106
. 127
k 131
b 161
h 186
g 201
f 235
u 279
m 293
n 432
c 451
r 451
l 460
d 472
i 516
a 529
o 532
p 593
s 660
t 662
e 710
#!/usr/bin/env bash
declare -A alph
dirs=(
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
)
for c in $(compgen -bk); do
for ((i=0; i<${#c}; i++)); do
p=${c:$i:1}
alph[$p]=$((${alph[$p]} + 1))
done
done
for dir in "${dirs[@]}"; do
commands=( $(find "$dir" -type f -exec basename {} \;) )
for c in "${commands[@]}"; do
for ((i=0; i<${#c}; i++)); do
p=${c:$i:1}
alph[$p]=$((${alph[$p]} + 1))
done
done
done
for i in "${!alph[@]}"; do
printf '%s\t%s\n' "$i" "${alph[$i]}"
done | sort -nk2,2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment