Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux append console output to a logfile?

Tags:

I know that I can let Linux to write the console output to a logfile by doing:

command > logfile.log 

But this overwrites whatever was in the logfile before. How do I make it append the output to the logfile rather than overwriting it?

like image 907
Wingblade Avatar asked Jul 14 '12 10:07

Wingblade


People also ask

How do I redirect console output 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.

How do you append the output of a command to a file in Linux?

Append Text Using >> Operator The >> operator redirects output to a file, if the file doesn't exist, it is created but if it exists, the output will be appended at the end of the file. For example, you can use the echo command to append the text to the end of the file as shown.

How do you pipe the output of a command to a file 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.


2 Answers

You can use >> for appending to the same logfile for e.g cmd1 >> logfile.log then use for other commnad like

cmd2 >> logfile.log 

>> is used for append data to the file

like image 90
Omkant Avatar answered Oct 19 '22 03:10

Omkant


just replace > for >>

like image 40
Mats Avatar answered Oct 19 '22 01:10

Mats