time: Tracking execution time

Many times in my life as a sysadmin I've needed to time how long a script or process takes to run. This was usually a manual task until I found the awesomeness of the time command.

Example:

[[email protected] ~]$ w  
09:51:24 up 4:41, 2 users, load average: 0.00, 0.01, 0.05  
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT  
bcane tty1 :0 18Aug11 8days 3.40s 0.06s pam: gdm-passwo  
bcane pts/0 :0.0 18Aug11 0.00s 0.03s 0.01s w


[[email protected] ~]$ time w  
09:52:58 up 4:42, 2 users, load average: 0.00, 0.01, 0.05  
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT  
bcane tty1 :0 18Aug11 8days 3.46s 0.06s pam: gdm-passwo  
bcane pts/0 :0.0 18Aug11 0.00s 0.02s 0.00s w  
  
real 0m0.022s 
user 0m0.002s 
sys 0m0.011s

Or if you want to get fancy you can encapsulate the commands with curly brackets.

[[email protected] ~]$ time { for x in /tmp/v*; do sleep 5; echo $x; done; }  
/tmp/virtual-bcane.Bkon89  
/tmp/virtual-bcane.v9Bm6L  
/tmp/virtual-bcane.WXwFtb  
  
real 0m15.072s  
user 0m0.001s  
sys 0m0.006s  
Avatar
Benjamin Cane
Principal Engineer, Vice President

Benjamin Cane is Principal Engineer at American Express. He has more than 16 years of experience with roles in both systems and software engineering. He leverages both his systems and software skills to build end-to-end platforms. Platforms, purpose built for performance and resiliency. Benjamin is also the author of Red Hat Enterprise Linux - Troubleshooting Guide (2015, Packt Publishing), and he has published many popular articles on topics such as Linux, Docker, Python, Go and Performance Tuning. Thoughts and Opinions expressed in my articles are my own.

Next
Previous

Related