Truncate Task

## Truncate

Since Apache Ant 1.7.1

### Description

Set the length of one or more files, as the `truncate` Unix function or GNU utility. In addition to working with a single file, this Task can also work on resources and resource collections.

### Parameters

Attribute | Description | Required
--- | --- | ---
file | The name of the file. | Unless a nested resource collection element has been specified
length | Specifies the new file length (in bytes) to set. The following suffixes are supported: K : Kilobytes (1024 bytes) M : Megabytes (1024 K) G : Gigabytes (1024 M) T : Terabytes (1024 G) P : Petabytes (1024 T) | At most one of these; omitting both implies length=0
adjust | Specifies the number of bytes (and positive/negative direction) by which to adjust file lengths. The same suffixes are supported for this attribute as for the length attribute.
create | Whether to create nonexistent files. | No; default true
mkdirs | Whether to create nonexistent parent directories when creating new files. | No; default false

### Parameters specified as nested elements

#### any resource collection

You can use any number of nested resource collection elements to define the resources for this task and refer to resources defined elsewhere. Note: resources passed to this task are expected to be filesystem-based.

### Examples

    <truncate file="foo"/>

Sets the length of file `foo` to zero.

    <truncate file="foo" length="1K"/>

Sets the length of file `foo` to 1 kilobyte (1024 bytes).

    <truncate file="foo" adjust="1K"/>

Adjusts the length of file `foo` upward by 1 kilobyte.

    <truncate file="foo" adjust="-1M"/>

Adjusts the length of file `foo` downward by 1 megabyte.