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 4, 2000 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 + | - 41.Ar size 42.Op K | M | G 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 54The 55.Nm 56utility adjusts the length of each regular file given on the command-line. 57.Pp 58The following options are available: 59.Bl -tag -width indent 60.It Fl c 61Do not create files if they do not exist. 62The 63.Nm 64utility does not treat this as an error. 65No error messages are displayed 66and the exit value is not affected. 67.It Fl r Ar rfile 68Truncate files to the length of the file 69.Ar rfile . 70.It Fl s Xo 71.Sm off 72.Op + | - 73.Ar size 74.Op K | M | G 75.Sm on 76.Xc 77If the 78.Ar size 79argument is preceded by a plus sign 80.Pq Sq + , 81files will be extended by this number of bytes. 82If the 83.Ar size 84argument is preceded by a dash 85.Pq Sq - , 86file lengths will be reduced by no more than this number of bytes, 87to a minimum length of zero bytes. 88Otherwise, the 89.Ar size 90argument specifies an absolute length to which all files 91should be extended or reduced as appropriate. 92.Pp 93The 94.Ar size 95argument may be suffixed with one of 96.Sq K , 97.Sq M , 98.Sq G 99to indicate a multiple of 100Kilobytes, Megabytes or Gigabytes 101respectively. 102.El 103.Pp 104Exactly one of the 105.Fl r 106and 107.Fl s 108options must be specified. 109.Pp 110If a file is made smaller, its extra data is lost. 111If a file is made larger, 112it will be extended as if by writing bytes with the value zero. 113If the file does not exist, 114it is created unless the 115.Fl c 116option is specified. 117.Pp 118Note that, 119while truncating a file causes space on disk to be freed, 120extending a file does not cause space to be allocated. 121To extend a file and actually allocate the space, 122it is necessary to explicitly write data to it, 123using (for example) the shell's 124.Ql >> 125redirection syntax, or 126.Xr dd 1 . 127.Sh DIAGNOSTICS 128The 129.Nm 130utility exits 0 on success, 131and >0 if an error occurs. 132If the operation fails for an argument, 133.Nm 134will issue a diagnostic 135and continue processing the remaining arguments. 136.Sh SEE ALSO 137.Xr dd 1 , 138.Xr touch 1 , 139.Xr truncate 2 140.Sh STANDARDS 141The 142.Nm 143utility conforms to no known standards. 144.Sh HISTORY 145The 146.Nm 147utility first appeared in 148.Fx 4.2 . 149.Sh AUTHORS 150The 151.Nm 152utility and this manual page were written by 153.An Sheldon Hearn 154.Aq sheldonh@uunet.co.za . 155