Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect the output of the "time" command?

I tried to redirect the output of the time command, but I couldn't:

$time ls > filename real    0m0.000s user    0m0.000s sys     0m0.000s 

In the file I can see the output of the ls command, not that of time. Please explain, why I couldn't and how to do this.

like image 590
abubacker Avatar asked Mar 09 '10 12:03

abubacker


People also ask

How do I redirect an output?

On a command line, redirection is the process of using the input/output of a file or command to use it as an input for another file. It is similar but different from pipes, as it allows reading/writing from files instead of only commands. Redirection can be done by using the operators > and >> .

How can you redirect the output of a command to a file?

To redirect the output of a command to a file, type the command, specify the > or the >> operator, and then provide the path to a file you want to the output redirected to. For example, the ls command lists the files and folders in the current directory.

Which command is used for output redirection?

Input/Output (I/O) redirection in Linux refers to the ability of the Linux operating system that allows us to change the standard input ( stdin ) and standard output ( stdout ) when executing a command on the terminal. By default, the standard input device is your keyboard and the standard output device is your screen.

How do I redirect the output of a command in Linux?

In Linux, for redirecting output to a file, utilize the ”>” and ”>>” redirection operators or the top command. Redirection allows you to save or redirect the output of a command in another file on your system. You can use it to save the outputs and use them later for different purposes.


1 Answers

no need to launch sub shell. Use a code block will do as well.

{ time ls; } 2> out.txt 

or

{ time ls > /dev/null 2>&1 ; } 2> out.txt 
like image 162
ghostdog74 Avatar answered Oct 12 '22 13:10

ghostdog74