]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/truncate/truncate.1
ident(1): Normalizing date format
[FreeBSD/FreeBSD.git] / usr.bin / truncate / truncate.1
1 .\"
2 .\" Copyright (c) 2000 Sheldon Hearn <sheldonh@FreeBSD.org>.
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd July 27, 2020
29 .Dt TRUNCATE 1
30 .Os
31 .Sh NAME
32 .Nm truncate
33 .Nd truncate or extend the length of files
34 .Sh SYNOPSIS
35 .Nm
36 .Op Fl c
37 .Bk -words
38 .Fl s Xo
39 .Sm off
40 .Op Cm + | - | % | /
41 .Ar size
42 .Op Cm K | k | M | m | G | g | T | t
43 .Sm on
44 .Xc
45 .Ek
46 .Ar
47 .Nm
48 .Op Fl c
49 .Bk -words
50 .Fl r Ar rfile
51 .Ek
52 .Ar
53 .Sh DESCRIPTION
54 The
55 .Nm
56 utility adjusts the length of each regular file given on the command-line.
57 .Pp
58 The following options are available:
59 .Bl -tag -width indent
60 .It Fl c
61 Do not create files if they do not exist.
62 The
63 .Nm
64 utility does not treat this as an error.
65 No error messages are displayed
66 and the exit value is not affected.
67 .It Fl r Ar rfile
68 Truncate or extend files to the length of the file
69 .Ar rfile .
70 .It Fl s Xo
71 .Sm off
72 .Op Cm + | - | % | /
73 .Ar size
74 .Op Cm K | k | M | m | G | g | T | t
75 .Sm on
76 .Xc
77 If the
78 .Ar size
79 argument is preceded by a plus sign
80 .Pq Cm + ,
81 files will be extended by this number of bytes.
82 If the
83 .Ar size
84 argument is preceded by a dash
85 .Pq Cm - ,
86 file lengths will be reduced by no more than this number of bytes,
87 to a minimum length of zero bytes.
88 If the
89 .Ar size
90 argument is preceded by a percent sign
91 .Pq Cm % ,
92 files will be round up to a multiple of this number of bytes.
93 If the
94 .Ar size
95 argument is preceded by a slash sign
96 .Pq Cm / ,
97 files will be round down to a multiple of this number of bytes,
98 to a minimum length of zero bytes.
99 Otherwise, the
100 .Ar size
101 argument specifies an absolute length to which all files
102 should be extended or reduced as appropriate.
103 .Pp
104 The
105 .Ar size
106 argument may be suffixed with one of
107 .Cm K ,
108 .Cm M ,
109 .Cm G
110 or
111 .Cm T
112 (either upper or lower case) to indicate a multiple of
113 Kilobytes, Megabytes, Gigabytes or Terabytes
114 respectively.
115 .El
116 .Pp
117 Exactly one of the
118 .Fl r
119 and
120 .Fl s
121 options must be specified.
122 .Pp
123 If a file is made smaller, its extra data is lost.
124 If a file is made larger,
125 it will be extended as if by writing bytes with the value zero.
126 If the file does not exist,
127 it is created unless the
128 .Fl c
129 option is specified.
130 .Pp
131 Note that,
132 while truncating a file causes space on disk to be freed,
133 extending a file does not cause space to be allocated.
134 To extend a file and actually allocate the space,
135 it is necessary to explicitly write data to it,
136 using (for example) the shell's
137 .Ql >>
138 redirection syntax, or
139 .Xr dd 1 .
140 .Sh EXIT STATUS
141 .Ex -std
142 If the operation fails for an argument,
143 .Nm
144 will issue a diagnostic
145 and continue processing the remaining arguments.
146 .Sh EXAMPLES
147 Adjust the size of the file
148 .Pa test_file
149 to 10 Megabytes but do not create it if it does not exist:
150 .Bd -literal -offset indent
151 truncate -c -s +10M test_file
152 .Ed
153 .Pp
154 Same as above but create the file if it does not exist:
155 .Bd -literal -offset indent
156 truncate -s +10M test_file
157 ls -l test_file
158 -rw-r--r--  1 root  wheel  10485760 Jul 22 18:48 test_file
159 .Ed
160 .Pp
161 Adjust the size of
162 .Pa test_file
163 to the size of the kernel and create another file
164 .Pa test_file2
165 with the same size:
166 .Bd -literal -offset indent
167 truncate -r /boot/kernel/kernel test_file test_file2
168 ls -l /boot/kernel/kernel test_file*
169 -r-xr-xr-x  1 root  wheel    31352552 May 15 14:18 /boot/kernel/kernel*
170 -rw-r--r--  1 root  wheel    31352552 Jul 22 19:15 test_file
171 -rw-r--r--  1 root  wheel    31352552 Jul 22 19:15 test_file2
172 .Ed
173 .Pp
174 Downsize
175 .Pa test_file
176 in 5 Megabytes:
177 .Bd -literal -offset indent
178 # truncate -s -5M test_file
179 ls -l test_file*
180 -rw-r--r--  1 root  wheel    26109672 Jul 22 19:17 test_file
181 -rw-r--r--  1 root  wheel    31352552 Jul 22 19:15 test_file2
182 .Ed
183 .Sh SEE ALSO
184 .Xr dd 1 ,
185 .Xr touch 1 ,
186 .Xr truncate 2
187 .Sh STANDARDS
188 The
189 .Nm
190 utility conforms to no known standards.
191 .Sh HISTORY
192 The
193 .Nm
194 utility first appeared in
195 .Fx 4.2 .
196 .Sh AUTHORS
197 The
198 .Nm
199 utility was written by
200 .An Sheldon Hearn Aq Mt sheldonh@starjuice.net .