尽管内容已清空,但打开文件仍保持增长

编程入门 行业动态 更新时间:2024-10-28 16:22:14
本文介绍了尽管内容已清空,但打开文件仍保持增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

尽管内容已清空,但打开文件仍保持增长

本文发布于:2023-10-29 17:12:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540285.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:清空   文件   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!