the command
time ./myprog
displays the time it took to run myprog on the screen. Now i would like to write this information to a text file.
How?
the command
time ./myprog
displays the time it took to run myprog on the screen. Now i would like to write this information to a text file.
How?
Without a path time is the shell built-in, and its output does not get redirected. Instead, you can use the time program, in /usr/bin/time which will write to stderr:
/usr/bin/time -p ./myprog 2> timing.txt && gedit timing.txt
I added -p so the output is similar to the output of the time built-in.
Edit: I should have tested this!
Kees is very correct. time is a shell builtin in most cases so its output doesn't flow through STDOUT like other programs would normally. You can use the command version sitting in but to save having two identical answers (or me deleting mine), here's another way to capture things that don't output in a traditional way.
bash -c "time ./myprog" 2>&1 > file.txt
Same principals as before exist. If you want gedit to load after this, wump on && gedit file.txt, if you want it to append, change > for >>.
If your command is very noisy and you just want the times, you could run the output through tail:
bash -c "time ./myprog" 2>&1 | tail -3 > file.txt && gedit file.txt
To just save it to a file just do this:
time ./myprog > file.txt
You don't need the .txt extension but it might help you. If you want to append to the file (instead of replacing it), swap the > for >>.
If you want this showing up in gedit specifically, you need to save it to a file and then open it in gedit. I can't see a way of piping the text directly into gedit without saving it first.
time ./myprog > file.txt && gedit file.txt