| Main index | Section 1 | 日本語 | Options |
The following options are available:
| | |
| Do not create files if they do not exist. The truncate utility does not treat this as an error. No error messages are displayed and the exit value is not affected. | |
| | |
| Truncate or extend files to the length of the file rfile. | |
| | |
| [+|-|%|/]size[SUFFIX]If the size argument is preceded by a plus sign ( +), files will be extended by this number of bytes. If the size argument is preceded by a dash ( -), file lengths will be reduced by no more than this number of bytes, to a minimum length of zero bytes. If the size argument is preceded by a percent sign ( %), files will be round up to a multiple of this number of bytes. If the size argument is preceded by a slash sign ( /), files will be round down to a multiple of this number of bytes, to a minimum length of zero bytes. Otherwise, the size argument specifies an absolute length to which all files should be extended or reduced as appropriate. | |
| | |
| Zero a region in the specified file. If the underlying file system of the given file supports hole-punching, file system space deallocation may be performed in the operation region. | |
| | |
| The space management operation is performed at the given offset bytes in the file. If this option is not specified, the operation is performed at the beginning of the file. | |
| | |
|
The length of the operation range in bytes.
This option must always be specified if option
| |
The size, offset and length arguments may be suffixed with one of K, M, G or T (either upper or lower case) to indicate a multiple of Kilobytes, Megabytes, Gigabytes or Terabytes respectively.
Exactly one of the
If a file is made smaller, its extra data is lost.
If a file is made larger,
it will be extended as if by writing bytes with the value zero.
If the file does not exist,
it is created unless the
Note that, while truncating a file causes space on disk to be freed, extending a file does not cause space to be allocated. To extend a file and actually allocate the space, it is necessary to explicitly write data to it, using (for example) the shell's ‘>>’ redirection syntax, or dd(1).
truncate -c -s 10M test_file
Same as above but create the file if it does not exist:
truncate -s 10M test_file ls -l test_file -rw-r--r-- 1 root wheel 10485760 Jul 22 18:48 test_file
Adjust the size of test_file to the size of the kernel and create another file test_file2 with the same size:
truncate -r /boot/kernel/kernel test_file test_file2 ls -l /boot/kernel/kernel test_file* -r-xr-xr-x 1 root wheel 31352552 May 15 14:18 /boot/kernel/kernel -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file2
Increase the size of the file test_file by 5 megabytes but do not create it if it does not exist:
truncate -s +5M test_file ls -l test_file* -rw-r--r-- 1 root wheel 36595432 Sep 20 19:17 test_file -rw-r--r-- 1 root wheel 31352552 Sep 20 19:15 test_file2
Reduce the size of the file test_file by 5 megabytes:
truncate -s -5M test_file ls -l test_file* -rw-r--r-- 1 root wheel 31352552 Jul 22 19:19 test_file -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file2
| TRUNCATE (1) | March 6, 2025 |
| Main index | Section 1 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | Today, the Unix equivalent of a power drill would have 20 dials and switches, come with a nonstandard plug, require the user to hand-wind the motor coil, and not accept 3/8" or 7/8" drill bits (though this would be documented in the BUGS section of its instruction manual). | ” |
| — The Unix Haters' handbook | ||