E
E
Eugene TI2020-01-02 15:43:00
linux
Eugene TI, 2020-01-02 15:43:00

How to split and merge files inplace?

How to cut or merge pieces of files on the command line without taking up extra space?
split and cat make new files. And it is necessary to redistribute the already existing data over several files and vice versa.
Fallocate (linux) does something similar - stupidly reserves existing free blocks for the file.
Here we need something the same, only with mother-of-pearl buttons.
Under 3 OS and CLI.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mayton2019, 2020-01-02
@mayton2019

Based on the standard file API, it is most likely impossible. I'll explain why. Linux operates on the file API at the level of open/close/seek/read/write commands. This is the basis that works for all file systems. If you go down to the level of some specific file system (for example, vfat), then you can probably cut the file into pieces that are a multiple of the file system block size without re-allocations. But this is a dirty hack that will only work as root and only for a specific file system. And only for special conditions (block boundary). In general, it is technically possible to do this, but the use of this utility will be of a "destructive" nature, like the utilities parted, fdisk, mkfs. * and others. I strongly doubt that such a utility will be useful and in demand. It's better to use the normal API.

S
Saboteur, 2020-01-02
@saboteur_kiev

You can't do that.
You can truncate a specific file through truncate, but it won't work to make several from one.
fallocate doesn't do that, it creates a file of the right size but doesn't fill it with data, it just tells the file system how much space it needs. But fallocate does not manage specific areas of the disk, and in principle it cannot cut existing data.
The only option is to read the file into memory, delete it on disk, and write a few out of memory. But it is clear that the file size is limited in this case. You can write. And in any case there will be read/write operations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question