Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect result of linux time command to some file

Tags:

linux

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?

like image 609
Julias Avatar asked Jun 18 '12 11:06

Julias


4 Answers

-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
like image 102
Adam Avatar answered Nov 12 '22 08:11

Adam


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)

like image 7
claasz Avatar answered Nov 12 '22 07:11

claasz


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.

like image 3
Levon Avatar answered Nov 12 '22 07:11

Levon


\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.

like image 1
ctrl-alt-delor Avatar answered Nov 12 '22 06:11

ctrl-alt-delor