\u5b89\u88c5<\/strong><\/div>\n\u901a\u5e38\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u5b89\u88c5truncate\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u5728coreutils\u5b89\u88c5\u5305\u91cc\u9762\uff0c\u5982\u679c\u6ca1\u6709\u5b89\u88c5\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n
\r\n[root@localhost ~]# yum provides truncate\r\nLoaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager\r\n\r\nThis system is not registered with an entitlement server. You can use subscription-manager to register.\r\n\r\nLoading mirror speeds from cached hostfile\r\n * base: mirrors.huaweicloud.com\r\n * extras: mirrors.aliyun.com\r\n * updates: mirrors.aliyun.com\r\ncoreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts\r\nRepo : base\r\nMatched from:\r\nFilename : \/usr\/bin\/truncate\r\n\r\ncoreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts\r\nRepo : @anaconda\r\nMatched from:\r\nFilename : \/usr\/bin\/truncate\r\n<\/pre>\n
\n\u53ef\u4ee5\u770b\u5230truncate\u7531coreutils\u5b89\u88c5\u5305\u63d0\u4f9b\uff0c\u4e0b\u9762\u5b89\u88c5coreutils\u5b89\u88c5\u5305\uff1a<\/p>\n
\r\n[root@localhost ~]# yum -y install coreutils\r\n<\/pre>\ntruncate\u5e38\u7528\u9009\u9879<\/strong><\/div>\n\u4e0b\u9762\u662ftruncate\u7684\u5e38\u7528\u9009\u9879\uff1a<\/p>\n
\r\n-c, --no-create --> \u4e0d\u521b\u5efa\u4efb\u4f55\u6587\u4ef6\r\n-o, --io-blocks --> \u5c06\u5927\u5c0f\u89c6\u4e3a\u5b58\u50a8\u5757\u7684\u6570\u91cf\uff0c\u800c\u4e0d\u662f\u5b57\u8282\r\n-r, --reference=RFILE --> \u53c2\u8003\u6307\u5b9a\u7684\u6587\u4ef6\u5927\u5c0f\r\n-s, --size=SIZE --> \u6309\u7167\u6307\u5b9a\u7684\u5b57\u8282\u8bbe\u7f6e\u6587\u4ef6\u5927\u5c0f\r\n<\/pre>\n\u4f7f\u7528truncate\u6e05\u9664\u6587\u4ef6\u5185\u5bb9<\/strong><\/div>\n\u8fd9\u5bf9\u4e8e\u6e05\u9664\u65e5\u5fd7\u6587\u4ef6\u5f88\u6709\u7528\u3002truncate\u8fc7\u7a0b\u57fa\u672c\u4e0a\u5220\u9664\u4e86\u6587\u4ef6\u7684\u6240\u6709\u5185\u5bb9\u3002\u5b83\u4e0d\u4f1a\u5220\u9664\u6587\u4ef6\u672c\u8eab\uff0c\u4f46\u4f1a\u5c06\u5b83\u4f5c\u4e3a\u96f6\u5b57\u8282\u6587\u4ef6\u4fdd\u7559\u5728\u78c1\u76d8\u4e0a\u3002\u4f8b\u5982\uff0c\u8ba9\u6211\u4eec\u4f7f\u7528truncate\u5c06\/var\/log\/yum.log\u6e05\u9664\u4e3a0\u4e2a\u5b57\u8282\u3002<\/p>\n
\r\n[root@localhost ~]# du -sh \/var\/log\/yum.log \r\n12K \/var\/log\/yum.log\r\n[root@localhost ~]# truncate -s 0 \/var\/log\/yum.log \r\n<\/pre>\n
\n\u518d\u6b21\u67e5\u770b\u8fd9\u4e2a\u6587\u4ef6\uff0c\u53d1\u73b0\u5b57\u8282\u4e3a0\u4e86\u3002\u67e5\u770b\u5185\u5bb9\u662f\u7a7a\u7684\u4e86\u3002<\/p>\n
\r\n[root@localhost ~]# du -sh \/var\/log\/yum.log \r\n0 \/var\/log\/yum.log\r\n[root@localhost ~]# cat \/var\/log\/yum.log \r\n<\/pre>\n
\ntruncate\u547d\u4ee4\u5c06\u4fdd\u7559\u6587\u4ef6\u6240\u6709\u6743\u3002\u53ef\u4ee5\u4f7f\u7528ll -h\u547d\u4ee4\u8fdb\u884c\u786e\u8ba4\uff1a<\/p>\n
\r\n[root@localhost ~]# ll -h \/var\/log\/yum.log \r\n-rw-------. 1 root root 0 Nov 4 18:39 \/var\/log\/yum.log\r\n<\/pre>\n<\/p>\n
\u4f7f\u7528truncate\u5c06\u6587\u4ef6\u8bbe\u7f6e\u4e3a\u6307\u5b9a\u5927\u5c0f<\/strong><\/div>\n\u4e0b\u9762\u7684\u793a\u4f8b\u5c06\u6587\u4ef6\u586b\u5145\u4e3a10K\u4e2a\u5b57\u8282\u3002<\/p>\n
\r\n[root@localhost ~]# touch file.txt\r\n[root@localhost ~]# ll -h file.txt \r\n-rw-r--r--. 1 root root 0 Nov 4 18:43 file.txt\r\n[root@localhost ~]# truncate -s 10k file.txt \r\n[root@localhost ~]# ll -h file.txt \r\n-rw-r--r--. 1 root root 10K Nov 4 18:43 file.txt\r\n<\/pre>\n\u5355\u4f4d\u6709 K, M, G, T, P, E, Z, Y\u3002<\/p>\n
\u4f7f\u7528truncate\u6269\u5c55\u6587\u4ef6\u5927\u5c0f<\/strong><\/div>\n\u4e5f\u53ef\u4ee5\u5c06\u6587\u4ef6\u7684\u5927\u5c0f\u4ece\u5f53\u524d\u6269\u5c55\u5230\u6240\u9700\u72b6\u6001\u3002\u4f7f\u7528-s\u9009\u9879\uff0c\u5728\u6570\u5b57\u524d\u9762\u52a0\u4e0a+<\/code><\/p>\n\r\n[root@localhost ~]# cat \/etc\/passwd > file.txt\r\n[root@localhost ~]# ll -h file.txt \r\n-rw-r--r--. 1 root root 1009 Nov 4 18:47 file.txt\r\n[root@localhost ~]# truncate -s +200k file.txt \r\n[root@localhost ~]# ll -h file.txt \r\n-rw-r--r--. 1 root root 201K Nov 4 18:47 file.txt\r\n<\/pre>\n
\n\u901a\u8fc7\u6dfb\u52a0\u989d\u5916\u7684200K\uff0c\u8fd9\u4f1a\u5c06\u6587\u4ef6\u5927\u5c0f\u4ece1K\u6269\u5c55\u5230201K\u3002<\/p>\n
\u4f7f\u7528truncate\u51cf\u5c0f\u6587\u4ef6\u5927\u5c0f<\/strong><\/div>\n\u5047\u8bbe\u6709\u4e00\u4e2a500K\u7684\u6587\u4ef6\uff0c\u5e76\u4e14\u5e0c\u671b\u5c06\u5176\u7f29\u5c0f\u5230250K\u3002\u5c06\u4f7f\u7528-s\u9009\u9879\uff0c\u5728\u6570\u5b57\u524d\u9762\u52a0\u4e0a-<\/code><\/p>\n\r\n[root@localhost ~]# touch file.txt\r\n[root@localhost ~]# truncate -s 500k file.txt \r\n[root@localhost ~]# ll -h\r\ntotal 4.0K\r\n-rw-------. 1 root root 1.3K Dec 29 2019 anaconda-ks.cfg\r\n-rw-r--r--. 1 root root 500K Nov 5 08:36 file.txt\r\ndrwxr-xr-x. 5 root root 107 Nov 4 18:22 test\r\n[root@localhost ~]# truncate -s -250k file.txt \r\n[root@localhost ~]# ll -h\r\ntotal 4.0K\r\n-rw-------. 1 root root 1.3K Dec 29 2019 anaconda-ks.cfg\r\n-rw-r--r--. 1 root root 250K Nov 5 08:36 file.txt\r\ndrwxr-xr-x. 5 root root 107 Nov 4 18:22 test\r\n<\/pre>\n
\n\u53ef\u4ee5\u770b\u5230\u5f53\u524d\u5927\u5c0f\u66f4\u6539\u4e3a250K\u3002<\/p>\n
\u603b\u7ed3<\/strong><\/div>\nTruncate\u547d\u4ee4\u901a\u5e38\u7528\u4e8e\u5c06\u6587\u4ef6\u7f29\u5c0f\u6216\u6269\u5c55\u5230\u6307\u5b9a\u7684\u5927\u5c0f\u3002\u5982\u679c\u6587\u4ef6\u5927\u4e8e\u6307\u5b9a\u7684\u5927\u5c0f\uff0c\u5219\u4f1a\u4e22\u5931\u989d\u5916\u7684\u6570\u636e\u3002\u5982\u679c\u6587\u4ef6\u8f83\u77ed\uff0c\u5219\u4f1a\u5bf9\u5176\u8fdb\u884c\u6269\u5c55\uff0c\u5e76\u4e14\u6269\u5c55\u90e8\u5206\u7684\u8bfb\u6570\u4e3a\u96f6\u5b57\u8282\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
Centos7 \u901a\u5e38\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u5b89\u88c5truncate\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u5728coreutils\u5b89\u88c5\u5305\u91cc\u9762\uff0c\u5982\u679c\u6ca1\u6709\u5b89\u88c5\u53ef\u4ee5 […]<\/p>\n","protected":false},"author":309,"featured_media":206000,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-205999","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=205999"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205999\/revisions"}],"predecessor-version":[{"id":206007,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205999\/revisions\/206007"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/206000"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=205999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=205999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=205999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}