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.

FWIW, this works okay:

andrewl$ ls -al junk.txt
-rw-r--r--   1 andrewl  andrewl  1073741824 Aug 28 01:45 junk.txt
andrewl$ ipython
Python 2.5.1 (r251:54863, Aug 19 2007, 00:42:28)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: ff = open("junk.txt", "wb")

In [2]: ff.truncate(500000000)

In [3]: ff.close()

In [4]:
Do you really want to exit ([y]/n)? y
andrewl$ ls -al junk.txt
-rw-r--r--   1 andrewl  andrewl  500000000 Aug 28 01:46 junk.txt

-a


--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to