1.\" 2.\" Copyright (c) 2019 Eugene Grosbein <eugen@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.Dd December 9, 2025 27.Dt TRIM 8 28.Os 29.Sh NAME 30.Nm trim 31.Nd erase device blocks that have no needed contents 32.Sh SYNOPSIS 33.Nm 34.Op Fl Nfqv 35.Fl [ [lo] Xo 36.Bk -words 37.Sm off 38.Ar offset 39.Op Cm K | k | M | m | G | g | T | t | P | p | E | e ] 40.Sm on 41.Xc 42.Ek 43.Bk -words 44.Op Fl r Ar rfile 45.Ek 46.Ar device ... 47.Sh DESCRIPTION 48The 49.Nm 50utility erases specified region of the device. 51It is mostly relevant for a storage that implements trim (like flash based, 52or thinly provisioned storage). 53.Sy All erased data is lost. 54.Pp 55The 56.Nm 57utility should not be used upon mounted file system or active devices 58being a part of imported ZFS pool or other software RAID, and the kernel 59does not permit such usage generally. 60If used upon not mounted file system 61or inactive device, the 62.Nm 63utility erases blocks non-selectively, whether a block is occupied or not. 64Refer to the 65.Xr fsck_ffs 8 66command having a flag 67.Fl E 68to trim free blocks inside populated UFS, and to the 69.Xr zpool-trim 8 70command to trim existing ZFS pool. 71.Pp 72The following options are available: 73.Bl -tag -width indent 74.It Fl N 75Do not actually erase anything but show what it would do (dry run). 76Implies 77.Fl v . 78This is the default. 79Overrides 80.Fl f . 81.It Fl f 82Perform the operation. 83Overrides 84.Fl N . 85.It Fl l Xo 86.Sm off 87.Ar offset 88.Op Cm K | k | M | m | G | g | T | t | P | p | E | e 89.Sm on 90.Xc 91.It Fl o Xo 92.Sm off 93.Ar offset 94.Op Cm K | k | M | m | G | g | T | t | P | p | E | e 95.Sm on 96.Xc 97Specify the length 98.Fl l 99of the region to trim or its offset 100.Fl o 101from the beginning of the device. 102.Sy The whole device is erased by default 103unless one or both of these options are presented. 104.Pp 105The argument may be suffixed with one of 106.Cm K , 107.Cm M , 108.Cm G , 109.Cm T , 110.Cm P 111or 112.Cm E 113(either upper or lower case) to indicate a multiple of 114Kilobytes, Megabytes, Gigabytes, Terabytes, Petabytes or 115Exabytes, respectively. 116.It Fl q 117Do not output anything except of possible error messages (quiet mode). 118Overrides 119.Fl v . 120.It Fl r Ar rfile 121Uses the length of given 122.Ar rfile 123as length of the region to erase. 124.Sy The whole device is erased by default. 125.It Fl v 126Show offset and length of actual region being erased, in bytes. 127.El 128.Pp 129Later options override previous ones. 130.Pp 131Note that actual success of the operation depends of underlying 132device driver such as 133.Xr ada 4 , 134.Xr da 4 135and others. 136Refer to corresponding manual pages for detail on possible caveats 137in low level support for ATA TRIM or SCSI UNMAP commands. 138.Sh EXIT STATUS 139.Ex -std 140If the final erase operation fails for an argument, the 141.Nm 142utility returns exit code 1. 143It can also return one of the exit codes defined in 144.Xr sysexits 3 , 145as follows: 146.Bl -tag -width ".Dv EX_UNAVAILABLE" 147.It Dv EX_USAGE 148The specified offset or length of the region is incorrect. 149.It Dv EX_OSERR 150There is no enough memory to proceed. 151.It Dv EX_NOINPUT 152The specified 153.Ar rfile 154cannot be opened (perhaps, it does not exist). 155.It Dv EX_IOERR 156The specified 157.Ar rfile 158cannot be examined for its size due to some system input/output error. 159.It Dv EX_DATAERR 160The specified 161.Ar rfile 162is not regular file, directory nor special device, so its size 163cannot be examined. 164.It Dv EX_UNAVAILABLE 165The specified 166.Ar rfile 167is special device file not supporting DIOCGMEDIASIZE 168.Xr ioctl 2 169(probably not a disk), so its size cannot be examined. 170.El 171.Sh SEE ALSO 172.Xr ioctl 2 , 173.Xr sysexits 3 , 174.Xr ada 4 , 175.Xr da 4 , 176.Xr nda 4 , 177.Xr fsck_ffs 8 , 178.Xr zpool-trim 8 179.Sh HISTORY 180The 181.Nm 182utility first appeared in 183.Fx 12.1 . 184.Sh AUTHORS 185The 186.Nm 187utility was written by 188.An Eugene Grosbein Aq Mt eugen@FreeBSD.org . 189