James G. Sack (jim) wrote:
Gus Wirth wrote:
Andrew Lentvorski wrote:
Is there a quick way to remove the last 10 bytes from a big honking file?
I asked this same question a while ago and the answer is no. Just about
every solution you get involves making a copy somewhat along the lines
of using dd to copy everything but the last few bytes. My application
was to trim the last block off a ISO image obtained by doing a dd of a
CDROM/DVD.
The problem arises because of the virtualization of file systems. It
takes direct intimate relations with the underlying file system to be
able to manipulate the file size indicators and to move the last pointer
/extent/branch/whatever-they-use-for-the-filesystem.
I've seen a reference to a utility for use on ext2 file systems, but I
can't remember what I did with it. I think fat and fat32 file systems
have simple utilities for trimming files left over from the DOS days
that may be "good enough" depending on what you are doing.
Beg to differ-
I have already mentioned
man 2 truncate
(it's part of POSIX, I believe)
and posted a perl script that performs the truncation asked for.
Guessing you are behind in your email processing. :-)
No. Just because the function works to trim the last few bytes doesn't
mean that it is quick. You haven't posted any benchmarks, and without
knowing how the function works we can't tell whether it is manipulating
the file system or doing a byte copy. If it's doing a byte copy then
it's the same as doing a dd.
Does the the function work on ext2fs, ext3fs, XFS, JFS, Reiser3, fat,
fat32, and any of the other numerous file systems that Linux supports?
Some of these file systems are not POSIX compliant, yet the nature of a
generic program like truncate suggests it should work on all of them. So
does truncate have intimate knowledge of all these file systems, or is
there something in the file system driver layer that allows truncation
as a general call so that it can be done efficiently?
This needs more research, which I probably won't get to before I leave,
so it's up to other to investigate this.
Gus
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list