[clug] Cut a file in place.

Alastair D'Silva alastair at d-silva.org
Tue Sep 17 00:16:04 UTC 2019


On Tue, 2019-09-17 at 09:31 +1000, Andrew Janke via linux wrote:
> Hi all,
> 
> Let's say I have a 26GB compressed archive and 17GB of spare disk
> space and
> want to cut it up into chunks. The internet says no, but this list
> typically doesn't fail me.
> 
> Chop a bit off the front and then use truncate the file?  Seems a
> risky way
> but the option that I'll have?
> 
> a


I think you're 90% of the way there. I would chop and save bits off the
end, as the truncate command operates on the end of a file.

You could write a bash script to do the following pseudocode:

chunk_size=1M
chunks=$file_size/$chunk_size

for ($i = $chunks; $i >= 0; $i--) {
	offset=$i * $chunk_size
	dd if=$file of=$file.$i bs=$chunk_size count=1 skip=$i
	truncate -s $offset $file
}

You should probably test this on something unimportant first...


-- 
Alastair D'Silva           mob: 0423 762 819
skype: alastair_dsilva    
Twitter: @EvilDeece
blog: http://alastair.d-silva.org





More information about the linux mailing list