在 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/