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
35 .Nd truncate, extend the length of files, or perform space management in files
78 utility adjusts the length of each regular file given on the command-line, or
79 performs space management with the given offset and the length over a regular
80 file given on the command-line.
82 The following options are available:
83 .Bl -tag -width indent
85 Do not create files if they do not exist.
88 utility does not treat this as an error.
89 No error messages are displayed
90 and the exit value is not affected.
92 Truncate or extend files to the length of the file
103 argument is preceded by a plus sign
105 files will be extended by this number of bytes.
108 argument is preceded by a dash
110 file lengths will be reduced by no more than this number of bytes,
111 to a minimum length of zero bytes.
114 argument is preceded by a percent sign
116 files will be round up to a multiple of this number of bytes.
119 argument is preceded by a slash sign
121 files will be round down to a multiple of this number of bytes,
122 to a minimum length of zero bytes.
125 argument specifies an absolute length to which all files
126 should be extended or reduced as appropriate.
128 Zero a region in the specified file.
129 If the underlying file system of the given file supports hole-punching,
130 file system space deallocation may be performed in the operation region.
132 The space management operation is performed at the given
135 If this option is not specified, the operation is performed at the beginning of the file.
137 The length of the operation range in bytes.
138 This option must always be specified if option
140 is specified, and must be greater than 0.
148 arguments may be suffixed with one of
154 (either upper or lower case) to indicate a multiple of
155 Kilobytes, Megabytes, Gigabytes or Terabytes
163 options must be specified.
165 If a file is made smaller, its extra data is lost.
166 If a file is made larger,
167 it will be extended as if by writing bytes with the value zero.
168 If the file does not exist,
169 it is created unless the
174 while truncating a file causes space on disk to be freed,
175 extending a file does not cause space to be allocated.
176 To extend a file and actually allocate the space,
177 it is necessary to explicitly write data to it,
178 using (for example) the shell's
180 redirection syntax, or
184 If the operation fails for an argument,
186 will issue a diagnostic
187 and continue processing the remaining arguments.
189 Adjust the size of the file
191 to 10 Megabytes but do not create it if it does not exist:
192 .Bd -literal -offset indent
193 truncate -c -s +10M test_file
196 Same as above but create the file if it does not exist:
197 .Bd -literal -offset indent
198 truncate -s +10M test_file
200 -rw-r--r-- 1 root wheel 10485760 Jul 22 18:48 test_file
205 to the size of the kernel and create another file
208 .Bd -literal -offset indent
209 truncate -r /boot/kernel/kernel test_file test_file2
210 ls -l /boot/kernel/kernel test_file*
211 -r-xr-xr-x 1 root wheel 31352552 May 15 14:18 /boot/kernel/kernel*
212 -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file
213 -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file2
219 .Bd -literal -offset indent
220 # truncate -s -5M test_file
222 -rw-r--r-- 1 root wheel 26109672 Jul 22 19:17 test_file
223 -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file2
233 utility conforms to no known standards.
237 utility first appeared in
242 utility was written by
243 .An Sheldon Hearn Aq Mt sheldonh@starjuice.net .
244 Hole-punching support of this
245 utility was developed by
246 .An Ka Ho Ng Aq Mt khng@FreeBSD.org .