Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Time command in Fish shell

📅 2015-Jun-08 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ bash, fish, time ⬩ 📚 Archive

Running the time command in the Bash shell, gives output split across the very familiar real, user and sys sections:

$ time ./do_something

real    0m1.210s
user    0m0.158s
sys 0m0.033s

However, running time in the Fish shell, gives output in a different format:

$ time ./do_something

0.38user 0.08system 0:07.34elapsed 6%CPU (0avgtext+0avgdata 20116maxresident)k
7968inputs+192outputs (89major+25318minor)pagefaults 0swaps

The difference in output is because these two time programs are different. The Bash time is a command internal to that shell. Fish does not have in inbuilt time command, so it runs the binary /usr/bin/time whose output is of the above format.

If you like the simple format of the Bash time command and want it under Fish, use the -p option of the time binary:

$ time -p ./do_something

real 1.81
user 0.17
sys 0.02

If you would like this to be the default output format of time in Fish, then add the below lines to your ~/.config/fish/config.fish file:

function time --description="Time just like in Bash"
    command time --portability $argv
end

Tried with: Time 1.7-24, Fish 2.1.1, Bash 4.3.11 and Ubuntu 14.04


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧