Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to configure your shell(bash) so that it times all the commands except the common ones(like ls or cd)?

so when I type some command like

command arg1 arg2

I would want my terminal to convert it into behind the scene

time command arg1 arg2
share|improve this question
1  
Maybe this will be of use to you: unix.stackexchange.com/questions/12059/… –  Rain Mar 30 '13 at 2:17
    
Define common. I use ls,cd,rm,mv,pwd,echo,mkdir,rmdir,cp,more,less,ps,diff etc etc every day. It would probably be better to configure your shell to time the few specific commands you actually want to time or all commands as described in the link that @Rain posted. –  terdon Mar 30 '13 at 2:18

2 Answers 2

up vote 2 down vote accepted

I believe an alias is the answer. create as many aliases as you want.

alias cp='time cp'

share|improve this answer
    
I haven't done this outside of scripting, so I don't know if alias is smart enough, but but it might be a good idea to use time \cp instead of time cp so it forces it to use the system cp command instead of the alias. –  Ben Richards Apr 3 '13 at 22:50

You just need to execute the following command to add the time stamp to the history:

export HISTTIMEFORMAT='%F %T '

Then if you logout and log back in whenever you invoke the history command you will see a time stamp for the commands you executed. Unfortunately it doesn't seem like it appends a time stamp to the .bash_history file in a user's local home profile. It would also appears it doesn't have a way of distinguishing common vs. uncommon executed commands.

share|improve this answer
    
Thanks for the reply. However, here I am referring "time" as a unix command time for benchmarking –  Alby Mar 30 '13 at 13:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.