栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在不读取整个文件的情况下从大文件的末尾删除X字节?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在不读取整个文件的情况下从大文件的末尾删除X字节?

使用功能

truncate

http://linux.die.net/man/2/truncate

int truncate(const char *path, off_t length);int ftruncate(int fd, off_t length);

truncate采用文件名
ftruncate采用打开的文件描述符

两者都将文件长度设置为,

length
因此它会被截断或拉长(在后一种情况下,文件的其余部分将填充为NULL / ZERO)。

[edit]
truncate(Linux shell命令)也将起作用

**SYNTAX**truncate -s integer <filename>  **OPTIONS**-s number specify the new file length. If the new length is smaller than the current filelength data is lost. If the new length is greater the file is padded with 0. You can specify a magnitude character to ease large numbers:b or B size is bytes.k size is 1000 bytes.K size is 1024 bytes.m size is 10^6 bytes.M size is 1024^2 bytes.g size is 10^9 bytes.G size is 1024^3 bytes.**EXAMPLES**To shrink a file to 10 bytes:truncate -s 10 /tmp/fooTo enlarge or shrink a file to 345 Megabytes:truncate -s 345M /tmp/foo

[/编辑]



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/409100.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号