Hacker News new | ask | show | jobs
by rbanffy 5811 days ago
Can you move, rename or replace an open file with current Windows? That's possibly one of the reasons why it's so hard to apply patches without rebooting a Windows box. And an endless annoyance when using a Windows desktop.
2 comments

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.

> 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.
That's not the point. On any decent Unix, you can overwrite any shared library that's being used and just reload the program. It's not about log files, but not having to bring down the machine in order to write an important file. That's why windows updates take eons: after the boot there are tons of files that have to be moved or renamed before the system can boot completely.

It's insane.