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 )) && 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 ) && 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

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin