Cat /dev/null file exists




















Reason: code tags Join Date: Jun How sure are you that this will work? Truncating an open file is not guaranteed to release the space it uses, and the process es that already have the file open could very well just write more data at their current offset, which at best will create a sparse file. The only way to make something like this work is if you have control of the application s generating the log file s. And if you have control of the application s , you don't need a kludge like this because you'd have the app s properly manage their log files.

It seems to have worked previously from what I've seen when running the command manually, so I see no reason why it wouldn't work now. Any suggestions? Join Date: Dec Join Date: Oct Here is something both optimized and a little cryptic : Code :. Originally Posted by jlliagre. Shell Programming and Scripting. This newline is not part of the command's output.

Improve this answer. Community Bot 1. Eliah Kagan Eliah Kagan k 51 51 gold badges silver badges bronze badges. You can go further and replace the useless echo -n by : or just nothing, given the fact the command does nothing anyway. Rather than echo -n I would recommend you use truncate - using a command designed for the purpose is, in my option, a little clearer to future readers of the script.

BoristheSpider I get your point about readability but the shell can do it a simpler way with an empty redirection. Thank you for pointing this out--I've expanded my answer to cover this option. If I'm going to to redirect from a named command, echo -n is self-documenting as to its purpose lying in its output. Rinzwind Rinzwind k 38 38 gold badges silver badges bronze badges. Llama I would recommend that truncate for this - why use an echo and a pipe when there is a command explicitly designed for this task.

BoristheSpider Why use a explicitly designed command when no command at all do the same job? Although I would hate to see your scripts Show 2 more comments. Are there also Bourne-style shells that won't redirect stdout from an empty command? EliahKagan No Bourne style shell I'm aware of won't redirect stdout from an empty command. This was already the case with the Unix version 7 original Bourne shell. Otherwise they could have simply used. Today's Posts.

Quick Links. Search Forums. Show Threads. Show Posts. Registered User. Join Date: Feb I am using AIX 5. Is there any other way to make a file clear or make its size of 0 bytes? The said offset is a property of the according file descriptor of the writing process - if another process truncates the file or writes itself to the file, this will not have any effect on the offset.

Suppose that process P opens a file for writing without appending, yielding file descriptor fd. Then the effect on the file size as stat reports it of truncating a file e. Specifically, on write to fd the system will move "seek" to the offset associated with fd , filling the space from the current end of file possibly to the beginning, if it was entirely truncated up to the offset with zeros.

However, if the file has grown larger in the mean time, writing to fd will overwrite the content of the file, beginning at the offset. A sparse file is a file that contains "holes", i. This is why du and ls disagree - du looks at the actual disk usage, while ls uses simply stat to extract the file size attribute.

Remedy: restart the process. The fact the reported size by ls is still high is just due by the writing process seeking to its expected idea of what the end of file should be before writing. Because there is "nothing" before the seek point, this shouldn't hurt. The only risk would be that you want to do backups or copies of the affected file with using a non sparse file aware tool.

Note that restarting the writing process won't "recover" the space as the file will stay "holey". If you really want the reported file size to be zeroed, you need to stop kill the writing process before blanking the file. This won't delete anything, at all. The correct way to truncate a file, is using shell redirectors or any kind of editor to remove the lines.



0コメント

  • 1000 / 1000