请教一个删除文件内容的命令
比如我有一个日志文件,我想把它的内容全部删除了,但是保留文件呀,
不是用rm
实在想有什么办法了,
echo "" >> soap.log 这样也不行的!
>a
回复内容太短了!
echo "ls">>soap.log
echo "" > log
true > my.log
cat /dev/null > my.log
>>在文件尾追加,> 文件存在先清空,不存在会创建
- Assembly code
几种方式对比:
1、echo "" > date[@test]$ echo test > date
[@test]$ cat date
test
[@test]$ echo "" > date
[@test]$ od -c date
0000000 n
0000001
可以看到,该方式在数据文件里还是有字符的
=======================
2、cat /dev/null > date[@test]$ echo test > date
[@test]$ cat date
test
[@test]$ cat /dev/null > date
[@test]$ od -c date
0000000
可以看到,很干净
===========================
3、true > date[@test]$ echo test > date
[@test]$ cat date
test
[@test]$ true > date
[@test]$ od -c date
0000000
[@test]$同2,很干净!
:> soap.log
echo "" > soap.log">" 覆盖是写入文件
">>" 不覆盖源文件内容,在文件尾写入内容!