2 .\" Copyright (c) 2000 Sheldon Hearn <sheldonh@FreeBSD.org>.
3 .\" All rights reserved.
4 .\" Copyright (c) 2021 The FreeBSD Foundation
6 .\" Portions of this manual page were written by Ka Ho Ng <khng@FreeBSD.org>
7 .\" under sponsorship from the FreeBSD Foundation.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 .Nd truncate, extend the length of files, or perform space management in files
80 utility adjusts the length of each regular file given on the command-line, or
81 performs space management with the given offset and the length over a regular
82 file given on the command-line.
84 The following options are available:
85 .Bl -tag -width indent
87 Do not create files if they do not exist.
90 utility does not treat this as an error.
91 No error messages are displayed
92 and the exit value is not affected.
94 Truncate or extend files to the length of the file
105 argument is preceded by a plus sign
107 files will be extended by this number of bytes.
110 argument is preceded by a dash
112 file lengths will be reduced by no more than this number of bytes,
113 to a minimum length of zero bytes.
116 argument is preceded by a percent sign
118 files will be round up to a multiple of this number of bytes.
121 argument is preceded by a slash sign
123 files will be round down to a multiple of this number of bytes,
124 to a minimum length of zero bytes.
127 argument specifies an absolute length to which all files
128 should be extended or reduced as appropriate.
130 Zero a region in the specified file.
131 If the underlying file system of the given file supports hole-punching,
132 file system space deallocation may be performed in the operation region.
134 The space management operation is performed at the given
137 If this option is not specified, the operation is performed at the beginning of the file.
139 The length of the operation range in bytes.
140 This option must always be specified if option
142 is specified, and must be greater than 0.
150 arguments may be suffixed with one of
156 (either upper or lower case) to indicate a multiple of
157 Kilobytes, Megabytes, Gigabytes or Terabytes
165 options must be specified.
167 If a file is made smaller, its extra data is lost.
168 If a file is made larger,
169 it will be extended as if by writing bytes with the value zero.
170 If the file does not exist,
171 it is created unless the
176 while truncating a file causes space on disk to be freed,
177 extending a file does not cause space to be allocated.
178 To extend a file and actually allocate the space,
179 it is necessary to explicitly write data to it,
180 using (for example) the shell's
182 redirection syntax, or
186 If the operation fails for an argument,
188 will issue a diagnostic
189 and continue processing the remaining arguments.
191 Adjust the size of the file
193 to 10 Megabytes but do not create it if it does not exist:
194 .Bd -literal -offset indent
195 truncate -c -s +10M test_file
198 Same as above but create the file if it does not exist:
199 .Bd -literal -offset indent
200 truncate -s +10M test_file
202 -rw-r--r-- 1 root wheel 10485760 Jul 22 18:48 test_file
207 to the size of the kernel and create another file
210 .Bd -literal -offset indent
211 truncate -r /boot/kernel/kernel test_file test_file2
212 ls -l /boot/kernel/kernel test_file*
213 -r-xr-xr-x 1 root wheel 31352552 May 15 14:18 /boot/kernel/kernel*
214 -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file
215 -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file2
221 .Bd -literal -offset indent
222 # truncate -s -5M test_file
224 -rw-r--r-- 1 root wheel 26109672 Jul 22 19:17 test_file
225 -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file2
235 utility conforms to no known standards.
239 utility first appeared in
244 utility was written by
245 .An Sheldon Hearn Aq Mt sheldonh@starjuice.net .
246 Hole-punching support of this
247 utility was developed by
248 .An Ka Ho Ng Aq Mt khng@FreeBSD.org .