我需要清除日志文件的内容。然后我尝试使用“cat /dev/null > logfile”。事实上,它有效!但是有一种我无法理解的奇怪行为。清除文件后立即显示为0字节的大小,但经过一次修改后,大小又恢复到以前的值。使用“du”我可以看到这个值是错误的。我做对了吗?我该如何纠正?
我的猫命令:
jorplov@sg0080b:/applications/fsc/base/logs> ls -lah
-rw-r--r-- 1 jorplov svcusr 10G 2013-11-15 05:18 sg0080b_jorplov_startup.log
jorplov@sg0080b:/applications/fsc/base/logs> df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg00-fsc 2.0G 1.8G 90M 96% /applications/fsc
jorplov@sg0080b:/applications/fsc/base/logs> cat /dev/null > sg0080b_jorplov_startup.log
jorplov@sg0080b:/applications/fsc/base/logs> df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg00-fsc 2.0G 365M 1.6G 20% /applications/fsc
jorplov@sg0080b:/applications/fsc/base/logs> ls -lah
total 20K
-rw-r--r-- 1 jorplov svcusr 0 2013-11-15 05:25 sg0080b_jorplov_startup.log
几秒钟后:
jorplov@sg0080b:/applications/fsc/base/logs> ls -lah
-rw-r--r-- 1 jorplov svcusr 10G 2013-11-15 05:26 sg0080b_jorplov_startup.log
jorplov@sg0080b:/applications/fsc/base/logs> stat sg0080b_jorplov_startup.log
File: `sg0080b_jorplov_startup.log'
Size: 10718153084 Blocks: 32 IO Block: 4096 regular file
Device: fd03h/64771d Inode: 82380 Links: 1
Access: (0644/-rw-r--r--) Uid: (30013/ jorplov) Gid: (21459/ svcusr)
Access: 2013-11-15 05:34:00.000000000 +0100
Modify: 2013-11-15 05:34:12.000000000 +0100
Change: 2013-11-15 05:34:12.000000000 +0100
第二次尝试:
jorplov@sg0080b:/applications/fsc/base/logs> > sg0080b_jorplov_startup.log
jorplov@sg0080b:/applications/fsc/base/logs> stat sg0080b_jorplov_startup.log
File: `sg0080b_jorplov_startup.log'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 82380 Links: 1
Access: (0644/-rw-r--r--) Uid: (30013/ jorplov) Gid: (21459/ svcusr)
Access: 2013-11-15 05:34:00.000000000 +0100
Modify: 2013-11-15 05:46:55.000000000 +0100
Change: 2013-11-15 05:46:55.000000000 +0100
jorplov@sg0080b:/applications/fsc/base/logs> ls -lah
-rw-r--r-- 1 jorplov svcusr 0 2013-11-15 05:46 sg0080b_jorplov_startup.log
再次,几秒钟后:
jorplov@sg0080b:/applications/fsc/base/logs> stat sg0080b_jorplov_startup.log
File: `sg0080b_jorplov_startup.log'
Size: 10718153546 Blocks: 32 IO Block: 4096 regular file
Device: fd03h/64771d Inode: 82380 Links: 1
Access: (0644/-rw-r--r--) Uid: (30013/ jorplov) Gid: (21459/ svcusr)
Access: 2013-11-15 05:34:00.000000000 +0100
Modify: 2013-11-15 05:53:12.000000000 +0100
Change: 2013-11-15 05:53:12.000000000 +0100
jorplov@sg0080b:/applications/fsc/base/logs> ls -lah
-rw-r--r-- 1 jorplov svcusr 10G 2013-11-15 05:53 sagm061_jorplov_startup.log
jorplov@sg0080b:/applications/fsc/base/logs> du -h sagm061_jorplov_startup.log
16K sagm061_jorplov_startup.log