2

Wondering if there is a way to run time command in Linux by default when certain commands are run.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

3

You may alias the commands that you want to time:

alias ls='time command ls'
alias firefox='time command firefox'

or, with shell functions:

ls ()  { time command ls "$@"; }
firefox ()  { time command firefox "$@"; }

The command command is not strictly needed in the aliases, but required in the shell function, or otherwise you get a nice infinite recursion that probably ends with a core-dump of the shell. The command command will bypass any shell function lookup for the command you're executing.

Kusalananda
  • 333,661