truncate – shrink or extend the size of a file to the specified size

A UNIX Command

$cat example.text
hello
$ls -l example.text
-rw-r--r-- 1 jeffrin jeffrin 6 Jun 21 02:32 example.text
$truncate -s 10 example.text
$ls -l example.text
-rw-r--r-- 1 jeffrin jeffrin 10 Jun 21 02:35 example.text
$hexdump example.text
0000000 10068 6c6c 0a6f 0000 0000
000000a
$cat example.text
hello
$truncate -s 9 example.text
$ls -l example.text
-rw-r--r-- 1 jeffrin jeffrin 9 Jun 21 02:36 example.text
$hexdump example.text
0000000 10068 6c6c 0a6f 0000 0000
0000009
$

UNIX Explanation

`truncate' shrinks  or extends the  size of each  FILE to
the specified size.If a FILE is larger than the specified
size, the extra  data is lost.  If a  FILE is shorter, it
is extended and the extended part (or hole) reads as zero
bytes.

 

Leave a Reply

Your email address will not be published. Required fields are marked *