Linux for blind general discussion
blinux-list at redhat.com
Tue Sep 26 04:10:43 UTC 2017
The truncate command will likely have an undesired side-effect: if the
file is smaller than the target size, it will be generally be padded with
binary zeroes to force it to be the specified size.
If pure truncation is desired, might I suggest the dd command instead:
dd if=input-file of=output-file bs=maxlength count=1
If the input-file is shorter than maxlength, output-file will be the
same as input-file (not padded to maxlength).
(warning: maxlength has a limit, but that limit is usually at least 100 Meg.)
On Mon, Sep 25, 2017 at 18:07:24PM -0400, Linux for blind general discussion wrote:
> This isn't what was requested, but I'm pretty certain it will be useful
> nonetheless. The truncate command can create a file and make it a
> specific number of characters in size. Truncation happens from the end of
> the file if too large. So truncate 10000 file.txt would make a file 10000
> characters in length. Editing that file in overwrite mode not insert mode
> change lines don't insert lines would use up the space for the character
> limit on the file. Saving an edit; then truncating the file again but to
> a different file name than the original then comm -2 file1 file2 would
> show lines only in file2 not in file1.
More information about the Blinux-list