Linxu清空文件的方法
1.使用cat/cp/dd命令及/dev/null设备来清空文件
命令示例:
cat /dev/null > test.txt
2.使用重定向
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# > test.txt
[root@centos7 ~]# du -h test.txt
0 test.txt
3.使用true命令
[root@centos7 ~]# du -h test.txt
4.0K test.txt
[root@centos7 ~]# true > test.txt
[root@centos7 ~]# du -h test.txt
0 test.txt