I'm trying to run a command using `time`, like `time ./prog`, and I want to keep the output minimal. Specifically, I only want to capture the first line that shows the 'real' time, like `real 0m0.004s` or just `0m0.004s`. Is there a simple way to achieve this?
3 Answers
You can customize the output to only show the real time using the `TIMEFORMAT` variable in bash. For example, you can set it like this: `TIMEFORMAT="real %3lR"; time ./prog`. This will limit the output to just the real time in your desired format. Just remember that using a proper `time` executable can change the output slightly, so keep that in mind!
Another approach is to use a pipeline with `head`. You can run something like `time ./prog | head -1` to get the first line, which should be the real time line. If you prefer using `sed`, you could also do `time ./prog | sed -n -e '/real/p'` to ensure you capture that line specifically.
You have a few options to get just the real time output. The simplest might be using `grep` like this: `time ./prog | grep "real"` to grab the line directly. Alternatively, you can also use `awk` to print it: `time ./prog | awk '/^real/{print $2}'` if you just want the time value without the label.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String