Hacker News new | ask | show | jobs
by wizard_2 5811 days ago
Can you remove a logfile on linux/unix while something is using it? Of course you can but the open file will stay around in limbo. It wont free up space, the program that holds it open will write to the deleted file, etc. Most linux programs will let you send it a nohup and it will close and reopen the logfile, that's something I haven't a clue about on windows.

I still pipe logs to a separate process that checks if the logfile is deleted and reopens/creates the logfile, its just easier.

2 comments

> Of course you can but the open file will stay around in limbo. It wont free up space, the program that holds it open will write to the deleted file, etc.

This is actually a feature, because it makes secure temp files possible.

> I still pipe logs to a separate process that ...

Note that logging is usually done in a separate process anyway, using the Syslog facility.

If your intention is to totally remove the space that's occupied by the log file, you'll probably want to pipe /dev/null into the file:

cat /dev/null > /path/to/logfile

That does not do what you think it does.

Your command will make /path/to/logfile fill up all available space on the disk. To truncate that file, which is probably what you wanted to do, you should

`echo > /path/to/logfile`

His command does exactly what he says it does. Your command truncates the file and then writes a newline into it.