AMAZING! TRY THIS IN WINDOWS! 😀

<code>

stat -c %s largefilelike.iso; # count bytes (1Byte = 8Bits) in this file
4700372991

truncate --size=-1 largefilelike.iso; # cut off last byte of this file

stat -c %s largefilelike.iso; # count again bytes in this file
4700372990

</code>

This actually uses the truncate system call, so it’s efficient and does it without creating a new file.

If you don’t have truncate but have a find with a printf, something like this will work, where find is used to determine the size and the math is done by bash with arithmetic expansion:

dd if=srcfile of=dstfile bs=1 count=$(( $( find srcfile -printf '%s' ) - 1 )) &amp;&amp; mv dstfile srcfile

or if you have perl, you can have perl do both the filesize calculation and the math:

dd if=srcfile of=dstfile bs=1 count=$( perl -e 'print((-s $ARGV[0]) -1 )' srcfile ) &amp;&amp; mv dstfile srcfile

Although, if you have perl, you can do:

perl -e 'truncate $ARGV[0], ((-s $ARGV[0]) - 1)' srcfile

and call the system call directly via perl.

creditz: https://www.quora.com/How-do-I-chop-off-just-the-last-byte-of-a-file-in-Bash

admin