0

I have a file that is constantly been written and is getting to big. I need to copy the existing one to another name and at the same time create a new file with the same name so the process that is writing on the file will not be interrupted.

Thanks.

Ncu
  • 3
  • 2

1 Answers1

3

with the same name so the process that is writing on the file will not be interrupted.

cp file file.new && > file 

will copy the file over to file.new and then empty the file. (don't use rm as that could crash your process).

You should use logrotate to have the system itself make compressed log files at certain events (certain size reached or a daily compression) See How to prevent logs from getting too big? for more on that.

Rinzwind
  • 309,379