Truncating a file while it's being used (Linux)

后端 未结 13 2139
名媛妹妹
名媛妹妹 2020-12-05 01:54

I have a process that\'s writing a lot of data to stdout, which I\'m redirecting to a log file. I\'d like to limit the size of the file by occasionally copying the current

13条回答
  •  眼角桃花
    2020-12-05 02:42

    Redirect the output using >> instead of >. This will allow you to truncate the file without the file growing back to its original size. Also, don't forget to redirect STDERR (2>&1).

    So the end result would be: myprogram >> myprogram.log 2>&1 &

提交回复
热议问题