How to strip a certain number of Bytes from the end of a file in bash

To crop the last n Bytes from a file you can use the truncate command.
[u_r_the_man@TESTBOX ~]$ truncate --size=-n <filename>
Where n represents the number of Bytes to cut from the end of <filename>. The advantage is that the command will cut the bytes straight from the file so you don’t have to redirect the output of a command (e.g. cut) to another file.

About Juergen Caris

I am 54yo, MSc(Dist) and BSc in Computer Science, German and working as a Senior Server Engineer for the NHS Lothian. I am responsible for the patient management system, called TrakCare. I am a UNIX/Linux guy, working in this sector for more than 20 years now. I am also interested in robotics, microprocessors, system monitoring, Home automation and programming.
This entry was posted in Bash, Beginner, Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published.