truncate.1
TRUNCATE(1)
TRUNCATE(1)
FreeBSD General Commands Manual
TRUNCATE(1)
truncate —
截断或延长文件的长度
truncate [-c] -s [+|- | %|/]size[K|k|M|m|G|g|T|t] file ... truncate [-c] -r rfile file ...
truncate 实用程序调整命令行中给出的每个常规文件的长度。
可以使用以下选项:
如果文件不存在,请不要创建它们。 truncate 实用程序不会将此视为错误。 不显示错误消息,退出值不受影响。
-r rfile
截断或扩展文件到文件 rfile 的长度。
-s [+|-|%|/]size[K|k|M|m|G|g|T|t]
如果 size 参数前面有加号 (+), 则文件将扩展此字节数。 如果 size 参数前面有一个破折号 (-), 则文件长度将减少不超过此字节数,最小长度为零字节。 如果 size 参数前面有百分号 (%), 则文件将向上舍入到此字节数的倍数。 如果 size 参数前面有斜杠 (/), 则文件将向下舍入到此字节数的倍数,最小长度为零字节。否则, size 参数指定一个绝对长度,所有文件都应该适当地扩展或缩减到该长度。
size 参数可以后缀为 K, M, G 或 T (大写或小写)之一,分别表示千字节、兆字节、千兆字节或太字节的倍数。
必须指定 -r 和 -s 选项之一。
如果文件变小,则其额外数据将丢失。 如果文件变大,它将被扩展,就好像通过写入值为零的字节一样。 如果文件不存在,除非指定 -c 选项,否则将创建它。
请注意,虽然截断文件会释放磁盘空间,但扩展文件不会导致分配空间。 要扩展文件并实际分配空间,必须使用(例如)shell 的 ‘>>’ 重定向语法或 dd(1) 显式地向其写入数据。
The truncate utility exits 0 on success, and >0 if an error occurs. 如果某个参数的操作失败,则 truncate 将发出诊断信息并继续处理剩余的参数。
将文件 test_file 的大小调整为 10 MB,但如果它不存在则不要创建它:
truncate -c -s +10M test_file
与上面相同,但如果文件不存在则创建文件:
truncate -s +10M test_file ls -l test_file -rw-r--r-- 1 root wheel 10485760 Jul 22 18:48 test_file
将 test_file 的大小调整为内核的大小,并创建另一个相同大小的文件 test_file2 :
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
将 test_file 缩小到 5 MB:
# truncate -s -5M test_file ls -l test_file* -rw-r--r-- 1 root wheel 26109672 Jul 22 19:17 test_file -rw-r--r-- 1 root wheel 31352552 Jul 22 19:15 test_file2
dd(1), touch(1), truncate(2)
truncate 实用程序不符合任何已知标准。
truncate 实用程序首先出现在 FreeBSD 4.2 中。
truncate 实用程序由 Sheldon Hearn <[email protected]> 编写。
July 27, 2020
FreeBSD 13.1-RELEASE
最后更新于
这有帮助吗?