[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3288
  • Last Modified:

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
0
opike
Asked:
opike
1 Solution
 
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
 
brettmjohnsonCommented:
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
 
opikeAuthor Commented:
truncate did the trick. thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now