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 6568 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 6568 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s