Truncating the first 100MB of a file in linux

后端 未结 8 2111
余生分开走
余生分开走 2020-12-13 10:11

I am referring to How can you concatenate two huge files with very little spare disk space?

I\'m in the midst of implementing the following:

  1. Allocate a
8条回答
  •  既然无缘
    2020-12-13 10:51

    Chopping off the beginning of a file is not possible with most file systems and there's no general API to do it; for example the truncate function only modifies the ending of a file.

    You may be able to do it with some file systems though. For example the ext4 file system recently got an ioctl that you may find useful: http://lwn.net/Articles/556136/


    Update: About a year after this answer was written, support for removing blocks from beginning and middle of files on ext4 and xfs file systems was added to the fallocate function, by way of the FALLOC_FL_COLLAPSE_RANGE mode. It's more convenient than using the low level iotcl's yourself.

    There's also a command line utility with the same name as the C function. Assuming your file is on a supported file system, this will delete the first 100MB:

    fallocate -c -o 0 -l 100MB yourfile
    

提交回复
热议问题