gpt4 book ai didi

file - 在 linux 上从头开始收缩(截断)文件

转载 作者:行者123 更新时间:2023-12-03 23:17:13 25 4
gpt4 key购买 nike

在 Linux(和/或在其他 Unix 上)是否可以从一开始就“收缩”文件?我想将它用于持久队列(没有现有的实现适合我的需要)。从文件末尾,我想可以使用 truncate()。

最佳答案

如果您使用的是 ext4、xfs 或其他一些现代文件系统,从 Linux Kernel 3.15 开始,您可以使用:

#include <fcntl.h>

int fallocate(int fd, int mode, off_t offset, off_t len);

FALLOC_FL_COLLAPSE_RANGE旗帜。

http://manpages.ubuntu.com/manpages/disco/en/man2/fallocate.2.html

关于file - 在 linux 上从头开始收缩(截断)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5098366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com