0

How can I count how often a specific program / command is launched under linux?

Can I avoid a wrapper-shell-script ?

I need to count and measure my build cycle to convince management of better tools :-)

Bastl
  • 1,431
  • 3
  • 14
  • 15

3 Answers3

0

systemtap's fork tracer could be he answer.Just adjust it to your needs.

Alexander Gorshenev
  • 2,769
  • 18
  • 33
0

This commend line will prompt the most frequently used commands you type :

history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr

That produce (in my case) :

 104 reset
 89 ll
 78 cd
 52 sudo
 45 ssh
 45 ./unittest.sh
 44 ps
 38 python
 37 man
 29 ls
Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
0

I'm not sure if an alias counts as a shell wrapper script ... if not, then something like the following will count the number of times the aliased command (ls in this case) is run. Create a file named ~/counter with a zero in it up front and this will increment it each time.

alias ls='awk "{print \$1+1}" ~/counter > ~/counter.new ; mv ~/counter.new ~/counter ; ls'
Mark Wilkins
  • 40,729
  • 5
  • 57
  • 110