Reputation: 481
I have a file that will always have a fixed 16 byte garbage set of characters appended to the end.
I want to run a bash command to remove those last 16 bytes. I found truncate
, but a command such as truncate -s 16 myfile.json
will truncate myfile.json
entire file size to 16 bytes which isn't what I want. Is there a command for truncating bytes off the end of a file?
Upvotes: 3
Views: 1866
Reputation: 123460
When a command does something very close to what you want, it's always worth checking the man
page:
SIZE may also be prefixed by one of the following modifying characters: '+' extend by, '-' reduce by, '<' at most, '>' at least, '/' round down to multiple of, '%' round up to multiple of.
So:
truncate -s -16 myfile.json
Upvotes: 9