I have a log file of size nearly 100 MB which is opened by some program and logging is continuously going on in that file. I want to delete the first 10MB from that file. Is there any way to do that without affecting the logging process into that file.
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
|
To skip the first 10MB, you can use
That will copy the original file to |
|||
|
|
|
There isn't a way to delete data from the start of a file in situ. The truncate call can trim data from the end, but there is no equivalent for trimming space arbitrarily. Therefore the best you can do is top copy the file skipping over the bits you don't want. |
|||||||
|
|
You need to make sure that the inode of the file open by one or more processes doesn't change in order to continue logging to it. To do this, do:
|
|||||||||
|

O_APPENDor not (>> logas opposed to> log). Is it OK to suspend it for a few milliseconds? For a few seconds? Has it got a mechanism by which it can be told to reopen its log file (like many daemons do upon receiving HUP). Answers to those questions would help find the best solution. – Stephane Chazelas Oct 5 '12 at 20:38