time command

time command uses std. error to give its result.
wn we type
$ time cat new\ file 2>/dev/null
its result shd not be printed. but its still being printed..
wts the prob ..??

eg .

[suhaas@localhost ~]$ time cat new\ file
#include<stdio.h>

int main()
{
printf("%d",macro);

}

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

[suhaas@localhost ~]$ time cat new\ file >/dev/null

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

but now wn im redirecting std. error to null still its result is being printed ..like
[suhaas@localhost ~]$ time cat new\ file 2>/dev/null
#include<stdio.h>

int main()
{
printf("%d",macro);

}

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

this last portion shdnt b there if its result is given by std error..but still its there. wts is the reason???

Why use time if you don't want its output?

{ time cat new\ file; } 2>/dev/null

2> only redirects errors to a file.

> will redirect normal output to a file.

@ishkawa
time command as i have earlier said uses std. error to give its output so while im using 2>/dev/null it shouldnt give any out put ..
but thats not the case ,..
n i wanted a reson fr that..

@cfajohnson
thankx [:)]

Time does not use stderr for normal ouput. stderr is for error messages. stdout is for normal output. Time uses stdout to send output unless something goes wrong and it has to send error messages. Then it will send error messages to stderr.

If you use a command like

time 2> /dev/null

you will still see output sent to stdout but not output sent to sdterr.

{ time ; } 2> /dev/null
check this...

can u tell me y
[user@localhost ~]$time cat new\ file > /dev/null

works

and
[user@localhost ~]$time cat new\ file 2> /dev/null

it doesnt work ...as we can c frm the 1st post.

for the 2nd one we have to use

[user@localhost ~]${ time cat new\ file ; } 2> /dev/null

then it works
y??

Because time, in your example, is probably the bash builtin. Test the difference between

$ time cat new\ file 2>/dev/null

and

$ /usr/bin/time cat new\ file 2>/dev/null

Please see the The UNIX and Linux Forums - Forum Rules: "don't write in cyberchat or cyberpunk style"

Case 1:

time cat new\ file 2> /dev/null

The time command runs the command line:

cat new\ file 2> /dev/null

Its stderr is sent to /dev/null; stderr for time is not redirected.

Case 2:

{ time cat new\ file; } 2> /dev/null

The output of the compound command, including time, is sent to /dev/null.