尽管内容已清空,但打开文件仍保持增长 [英] Open File keeps growing despite emptied content

查看:65
本文介绍了尽管内容已清空,但打开文件仍保持增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文本流传输到文件中,并且在文件仍处于使用状态时,将其擦除以进行作业轮换?

How can I pipe a text stream into a file and, while the file is still in use, wipe it for job rotation?

长版:

我一直在努力解决一个似乎很小的问题,这使我的实验无法继续进行.

I've been struggling for a while onto an apparently minor issue, that's making my experiments impossible to continue.

我有一个软件可以从外部硬件(无线电镜项目)连续收集数据并以csv格式存储.作为远程安装,我将每天一次在安全的地方复制保存的数据并擦除文件内容,而出于同样的原因,我无法停止硬件/软件,因此不能停止诸如日志轮换之类的软件不会是一个选择.

I have a software collecting data continuously from external hardware (radiotelescope project) and storing in a csv format. Being the installation at a remote location I would, once a day, copy the saved data in a secure place and wipe the file content while, for the same reason, I can NOT to stop the hardware/software, thus software such as log rotation wouldn't be an option.

花了很多精力请参阅我的上一篇文章,清除的文件虽然为空,但仍在增长.

For as much effort spent see my previous post, it seems the wiped file keeps growing although empty.

Bizarre行为,显示文件大小,截断文件,再次显示文件大小:

Bizarre behavior, showing file size, truncate file, show file size again:

pi@tower /media/data $ ls -la radio.csv ;ls -s radio.csv;truncate radio.csv -s 1; ls -la radio.csv ;ls -s radio.csv
-rw-r--r-- 1 pi pi 994277 Jan 18 21:32 radio.csv
252 radio.csv
-rw-r--r-- 1 pi pi 1 Jan 18 21:32 radio.csv
0 radio.csv

然后,一旦有更多数据输入:

Then, as soon as more data comes in:

pi@tower /media/data $ ls -la radio.csv ;ls -s radio.csv
-rw-r--r-- 1 pi pi 1011130 Jan 18 21:32 radio.csv
24 radio.csv

我想将输出传递到sed命令中并立即保存,完全没有运气.另外,文件系统/硬件似乎没有故障(尝试了不同的硬件/发行版/文件系统).

I thought to pipe the output into a sed command and save right away, with no luck altogether. Also, filesystem/hardware doesn't seems buggy (tried different hardware/distro/filesystem).

有人会很高兴给我提示如何进行吗?

Would anyone be so nice to give me a hint how to proceed?

谢谢.

推荐答案

通过-a选项插入tee.该文件已通过原始来源保持打开状态.

Piped into tee with -a option. The file was kept open by originating source.

选项APPEND有助于坚持使用EOF新数据;在给定的问题中,将文件归零后追加到开头.

Option APPEND of tee helped to stick at the EOF new data; in the given issue, appending to the beginning when file zeroed.

有关搜索引擎和将来的参考资料:

For search engine and future reference:

sudo rtl_power -f 88M:108M:10k -g 1 - | tee -a radio.csv -

现在使用清空文件

echo -n > radio.csv

将文件按预期方式归零.

gets the file zeroed as expected.

这篇关于尽管内容已清空,但打开文件仍保持增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆