Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
that one actually solved the problem. Thanks again. – user2413 Nov 2 '10 at 18:27

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

Old answer

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
share|improve this answer
nice one =D! I actually learned something (>>) +1 – RolandiXor Nov 2 '10 at 18:09
> it does not work:> the file (file.txt) is indeed created but remains empty. What did i do wrong ? PS: i actually have to type './myprog ./ mydatat' to use myprog. Can it be because of this ? – user2413 Nov 2 '10 at 18:25
@kwak I updated the post. – Oli Nov 2 '10 at 18:42
> thanks. I already accepted Kees's answer, but both solve my problem. (i.e. i have up voted both). – user2413 Nov 2 '10 at 18:48
@kwak I've no problem with that - They both do pretty much the same thing. I just wanted to show a different way of doing this just in case somebody else has an issue with output redirection. – Oli Nov 2 '10 at 19:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.