I'm running the following command (on Ubuntu)

time wget 'http://localhost:8080/upLoading.jsp' --timeout=0

and get a result in the command line

real    0m0.042s
user    0m0.000s
sys     0m0.000s

I've tried the following:

time -a o.txt wget 'http://localhost:8080/upLoading.jsp' --timeout=0 

and get the following error

-a: command not found

I want to get the result to be redirected to some file. How can I do that?

share|improve this question
    
Probably you are using bash, and it has time built-in command. (see help time) Your command should use /usr/bin/time to work properly (to discover where the binary of time is use which time). Considering this, you must use: time -o out.txt -a ... – Lourenco Jul 8 '16 at 23:00
up vote 3 down vote accepted

You can direct the stdout output of any commmand to a file using the > character. To append the output to a file use >>

Note that unless done explicitly, output to stderr will still go to the console. To direct both stderr and stdout to the same output stream use

   command 2>&1 outfile.txt (with bash)

or

   command >& outfile.txt (with t/csh)

If you are working with bash All about redirection will give you more details and control about redirection.

share|improve this answer
3  
the (time wget ... ) 2> out.txt is working perfect. Thanks – Julias Jun 18 '12 at 14:56
    
Consider /usr/bin/time as I commented above. And so, use something like /usr/bin/time -o outfile.txt -a ... – Lourenco Jul 8 '16 at 23:02

-a is only understood by the time binary (/usr/bin/time), When just using time you're using the bash built-in version which does not process the -a option, and hence tries to run it as a command.

/usr/bin/time -o foo.txt -a wget 'http://localhost:8080/upLoading.jsp' --timeout=0
share|improve this answer
    
the both -a and -o did not worked. The solution was 2 > foo.txt – Julias Jun 18 '12 at 14:52
2  
I believe this is actually the correct answer. When calling time, call /usr/bin/time instead of using the shell's builtin which does not support the advanced options. – mattismyname May 10 '13 at 17:03
    
Definitely, this is the correct answer. – Lourenco Jul 8 '16 at 23:07
    
... as long as you are using linux, I guess. OS X's usr/bin/time doesn't support -o. – Sebastian Graf Jul 29 '16 at 12:31

Checking man time, I guess what you need is

time -o o.txt -a ...

(Note you need both -a and -o).

[EDIT:] If you are in bash, you must also take care to write

/usr/bin/time

(check manpage for explanation)

share|improve this answer
    
Still not working: -o: command not found on my machine. – Lev Levitsky Jun 18 '12 at 11:58
1  
Check Adam's comment (stackoverflow.com/a/11082413/384689), this is probably the solution – claasz Jun 18 '12 at 12:04
    
Hhmm, I cannot see it neither ... so I edited my answer. Hope this helps – claasz Jun 18 '12 at 12:09
    
It's back :) thanks – Lev Levitsky Jun 18 '12 at 12:09
    
I added a comment to this consideration in the question and also commented in the accepted answer. – Lourenco Jul 8 '16 at 23:04
\time 2> time.out.text command

\time -o time.out.text command

This answer based on earlier comments. It is tested it works. The advantage of the \ over /usr/bin/ is that you don't have to know the install directory of time.

These answers also only capture the time, not other output.

share|improve this answer

Exactly the time from GNU writes it's output to stderr and if you want to redirect it to file, you can use --output=PATH parameter of time

See this http://unixhelp.ed.ac.uk/CGI/man-cgi?time

And if you want to redirect stdout to some file, you can use > filename to create file and fill it or >> filename to append to some file after the initial command.

If you want to redirect stderr by yourself, you can use $ command >&2 your_stderr_output

share|improve this answer

Try to use /usr/bin/time since many shells have their own implementation of time which may or may not support the same flags as /usr/bin/time

so change your command to

  /usr/bin/time -a -o foo.txt wget ....
share|improve this answer
    
I added this comment in the question to evince it. – Lourenco Jul 8 '16 at 23:05

How about your LANG ?

$ time -ao o.txt echo 1
bash: -ao: コマンドが見つかりません

real    0m0.001s
user    0m0.000s
sys     0m0.000s
$ export|grep LANG
declare -x LANG="ja_JP.utf8"

$ LANG=C time -ao o.txt echo 1
1

$ cat o.txt
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 1984maxresident)k
0inputs+0outputs (0major+158minor)pagefaults 0swaps
share|improve this answer

Try:

command 2> log.txt

and the real-time output from "command" can be seen in another console window with:

tail -f log.txt
share|improve this answer

You can do that with > if you want to redirect the output.

For example:

time wget 'http://localhost:8080/upLoading.jsp' --timeout=0 > output.txt 2>&1

2>&1 says to redirect STDERR to the same file.

This command will erase any output.txt files and creates a new one with your output. If you use >> it will append the output at the end of any existing output.txt file. If it doesn't exist, it will create it.

share|improve this answer

Your Answer

 
discard

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.