truncate a file

Is there a way to truncate a file while it is open and being written to? I'm using an application that hasn't been set up with log file rolling and I'm trying to manange it externally.

Thanks,
Ollie
opikeAsked:
Who is Participating?
 
brettmjohnsonConnect With a Mentor Commented:
Have you tried ftruncate?  Excerpt from the man page:

     #include <unistd.h>

     int ftruncate(int fd, off_t length);

     ftruncate() causes the file referenced by fd to be truncated or
     extended to length bytes in size.  If the file previously was
     larger than this size, the extra data is lost. If the file was smaller
     than this size, it will be extended as if by writing bytes with the value
     zero.  With ftruncate(), the file must be open for writing.
0
 
sunnycoderCommented:
Hi opike,

> Is there a way to truncate a file while it is open and being written to?

Can try

echo > filename

Cheers!
Sunnycoder
0
 
opikeAuthor Commented:
truncate did the trick. thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.