2

I want to get the result of time command into a text file but it's not working it only put blank space in the text file.

I already tried this commands,

A-

$ x=`time`
$ echo $x > log.txt
$ cat log.txt

$

B-

$ time > log.txt

real    0m0.000s
user    0m0.000s
sys     0m0.000s
$ cat log.txt

$

C-

$ time > log.txt 2>&1

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

$ cat log.txt

$ 

What I really want is this.

$ time > log.txt
$ cat log.txt

real    0m0.000s
user    0m0.000s
sys     0m0.000s
Edmhar
  • 395

1 Answers1

2

Use the external time command instead of the builtin:

/usr/bin/time -po log.txt true
\time -po log.txt true   # simpler way

For example:

$ \time -po log.txt true
$ cat log.txt
real 0.00
user 0.00
sys 0.00
muru
  • 72,889