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
  • 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

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

alias cp='time cp'

  • 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:


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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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