Linux append console output to a logfile?

2019-03-24 03:31发布

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?

5条回答
We Are One
2楼-- · 2019-03-24 03:54

Change the operator:

command >> logfile.log
查看更多
来,给爷笑一个
3楼-- · 2019-03-24 04:03

A couple ways:

1) Uses io piping as follows:

$> echo 'some text' >> file.txt (will be appended)

2) Using a program like sed:

$> cat file.txt

some text

$> sed -i '$ a\ here is some more text' file.txt (will also be appended, without piping)

Gl hf!

查看更多
在下西门庆
4楼-- · 2019-03-24 04:08

Use command >> logfile.log

查看更多
何必那么认真
5楼-- · 2019-03-24 04:09

just replace > for >>

查看更多
你好瞎i
6楼-- · 2019-03-24 04:11

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

查看更多
登录 后发表回答