linux清空文件内容方法

[root@dbrg-2 ~]# vi mbox

iiii
~
root@dbrg-2 ~]# >mbox
[root@dbrg-2 ~]# more mbox
[root@dbrg-2 ~]# vi mbox

iiii

~                                                                                                                                                                                                                                  “mbox” 1L, 5C 已写 入
[root@dbrg-2 ~]# more mbox
iiii
[root@dbrg-2 ~]# :>mbox
[root@dbrg-2 ~]# more mbox

[root@dbrg-2 ~]# echo “haha” >mbox
[root@dbrg-2 ~]# more mbox
haha
[root@dbrg-2 ~]# echo “” > mbox
[root@dbrg-2 ~]# more mbox
[root@dbrg-2 ~]# more arp.txt
00:1f:3c:10:82:d2
00:e0:4c:02:54:14
00:1d:0f:06:36:39
00:e0:4c:02:48:5e
00:1f:3c:0f:0c:0d
00:16:76:17:68:d9
[root@dbrg-2 ~]# echo >arp.txt
[root@dbrg-2 ~]# more arp.txt

[root@dbrg-2 ~]#

[root@dbrg-2 ~]# echo “haha” >mbox

[root@dbrg-2 ~]# cp /dev/null mbox
cp:是否覆盖‘mbox’? y
[root@dbrg-2 ~]# more mbox

[root@dbrg-2 ~]# echo “haha” >mbox
[root@dbrg-2 ~]# more mbox
haha

[root@dbrg-2 ~]# cat /dev/null >mbox
[root@dbrg-2 ~]# more mbox
[root@dbrg-2 ~]#
[root@dbrg-2 ~]# more arp.txt
00:1f:3c:10:82:d2
00:e0:4c:02:54:14
00:1d:0f:06:36:39
00:e0:4c:02:48:5e
00:1f:3c:0f:0c:0d
00:1f:3c:74:25:b0
00:1b:77:6f:73:6e
00:1f:3c:cf:d2:68
00:1f:d0:0d:f7:12
[root@dbrg-2 ~]# sed -i ‘1,$’d arp.txt
[root@dbrg-2 ~]# more arp.txt
[root@dbrg-2 ~]#

发表评论

电子邮件地址不会被公开。 必填项已用*标注