Counting commands frequency


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting commands frequency
# 1  
Old 11-21-2009
Counting commands frequency

I'd like to create a script that keeps track of the commands used.
For example:

count ls ps

and from now on whenever I use ls or ps a counter is increased.
I want that after the command count has been activated a session starts(here I can use any commands) and I want to stop the session with a special command(quit for example).
In the end I want to print the result.
I'm a beginner in shell scripting and I don't know how to allow the shell continuing his work after my command has started.

Thank you in advance.
# 2  
Old 11-21-2009
Couple of ways to approach that.

If you are using bash, and have a reasonably large history file set, you can grep the count from "history"

You could also turn on system accounting - "accton".
# 3  
Old 11-21-2009
Thank you.
But I don't know how write the command.
grep "ls" history doesn't work.
# 4  
Old 11-22-2009
Code:
history |awk '$1=" "' |sort |uniq -c |sort -n

# 5  
Old 11-22-2009
What does awk actually do?
I read that combines grep and sed commands but I don't understand this '$1=" "'.
It works only if I don't create a script.
What should I do to make a working script of that code?

Thank you anyway.
# 6  
Old 11-22-2009
history command will give both order number and commands, such as:

Code:
  10  find . -type d 
   11  ls

with awk '$1=" "', it will remove the first column.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find frequency

Hi, I have a file with more than 1 million records.. Each row has a distance number.. I want to know how many times is each number occurring from min to max number.. 2 5 120 208 7 28 45 6 33 120 7 208 so onn.. output 0-0 (4 Replies)
Discussion started by: Diya123
4 Replies

2. Emergency UNIX and Linux Support

Different OS Kernel Update Frequency

Hi guys I'm trying to configure a collaboration suit (PHP, PostgreSQL, Apache) plus a mail server(Sendmail and Dovecot) on a single box. It will be used heavily 24*7. So having a long up time is really needed. I'm looking for 3 to 6 month up time. I want to know about kernel update... (6 Replies)
Discussion started by: majid.merkava
6 Replies

3. Shell Programming and Scripting

Bash - Same frequency

Hi, Could anyone help me with the following question, if I have two colums (names and frequency) as follows in a file called name.txt Michael 1 Jones 1 Ben 2 Rebeca 4 David 1 and I want to use bash script called freqnames.sh that takes one argument (name) and the output should be... (3 Replies)
Discussion started by: jboy
3 Replies

4. AIX

Finding Memory Frequency

Hi, I would like to know how to find out frequency of memory, I have used the command prtconf but it is showing amt of ram available on server, it is not showing frequency. Regards, Manoj (1 Reply)
Discussion started by: manoj.solaris
1 Replies

5. Shell Programming and Scripting

Word Frequency Sort

hello, Here is a program for creating a word-frequency # wf.gk --- program to generate word frequencies from a file { # remove punctuation: This will remove all punctuations from the file gsub(/_]/, "", $0) #Start frequency analysis for (i = 1; i <= NF; i++) freq++ } END #Print output... (11 Replies)
Discussion started by: gimley
11 Replies

6. UNIX for Dummies Questions & Answers

How to calculate frequency distributions?

Hello, I'm trying to get lists of the frequency distributions for each of two variables (vars C and N in the examples). I'd like the distribution for each variable to range from the min of the two variables to the max of the two variables. I can work out the max value beforehand by ordering the... (2 Replies)
Discussion started by: auburn
2 Replies

7. Shell Programming and Scripting

Sorting value frequency within an array

How is it possible to sort different nummeric values within an Array. But i don`t want the highest or the lowest. I need the most frequently occurring value. For examble: My Array has to following values = (200 404 404 500 404 404 404 200 404) The result should be 404 The values are... (3 Replies)
Discussion started by: 2retti
3 Replies

8. Solaris

out of frequency

:cool: after installing solaris 10 5/08/09 directory the computer rebooting then the massage "out of frequency" appear.i want a solution first second my main board is GA-MA780G UD3H (14 Replies)
Discussion started by: medo2008
14 Replies

9. HP-UX

How to find processor frequency

Hello , Please tell me how to find processor frequency in HP UNIX . (8 Replies)
Discussion started by: manjunath
8 Replies
Login or Register to Ask a Question