In the past, on linux systems, I've been able to truncate large, open log files (that is, a file that is being actively written to by a process) using cat /dev/null > file.log
.
However, on 10.9 (Mavericks), that doesn't seem to be the case. I've got an 11GB file that is being logged to by an application, but when I perform the same command with said file, nothing seems to happen.
When I try this on a file of trivial size, it does work.
Here is ls -l /dev/null
:
crw-rw-rw- 1 root wheel 3, 2 Dec 16 12:49 /dev/null
I've also tried cp /dev/null file.log
to no avail.
Thinking that I might take advantage of the truncate function (man 2 truncate
in Darwin) I compiled this and ran it against two files, one of trivial size and the other the actual log file. Again, it worked against the trivial file and did not work on the much larger log.
/*
* Copyright (c) 2013 Thomas de Grivel <thomas@lowh.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
...
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <unistd.h>
int main (int argc, const char **argv)
{
int e = 0;
while (--argc) {
argv++;
if (truncate(*argv, 0)) {
e = 4;
warn("%s", *argv);
}
}
return e;
}
The process returns 0
regardless of which file I use.
du
ordu -h
say? Is it possible the file is a sparse file?du -h /tmp/file.log
results in11G /tmp/file.log