想要把一个文件中的log日志内容清空。
搜:
linux 清空文件 命令
参考:
linux几种快速清空文件内容的方法 – nanyun2010的专栏 – 博客频道 – CSDN.NET
结果试了试:
echo “” > logs/rq_worker.log |
没用:
(RunningFast) ➜ staging echo “” > logs/rq_worker.log (RunningFast) ➜ staging cat logs/rq_worker.log ^C (RunningFast) ➜ staging ll logs total 7.7M -rw-r–r– 1 root root 604K Nov 7 14:19 gunicorn.err -rw-r–r– 1 root root 0 Nov 5 16:37 gunicorn.log -rw-r–r– 1 root root 13K Nov 7 14:24 redis.log -rw-r–r– 1 root root 737K Nov 7 14:27 rqscheduler.log -rw-r–r– 1 root root 95M Nov 7 14:27 rq_worker.log -rw-r–r– 1 root root 1008K Nov 7 14:27 RunningFast.log -rw-r–r– 1 root root 2.0M Nov 7 13:51 RunningFast.log.1 -rw-r–r– 1 root root 2.0M Nov 7 12:56 RunningFast.log.2 -rw-r–r– 1 root root 2.0M Nov 7 12:00 RunningFast.log.3 |
结果发现其实是可以的:
(RunningFast) ➜ staging echo “” > logs/RunningFast.log.1 (RunningFast) ➜ staging ll logs total 6.2M -rw-r–r– 1 root root 604K Nov 7 14:19 gunicorn.err -rw-r–r– 1 root root 0 Nov 5 16:37 gunicorn.log -rw-r–r– 1 root root 13K Nov 7 14:29 redis.log -rw-r–r– 1 root root 738K Nov 7 14:30 rqscheduler.log -rw-r–r– 1 root root 95M Nov 7 14:30 rq_worker.log -rw-r–r– 1 root root 1.2M Nov 7 14:30 RunningFast.log -rw-r–r– 1 root root 1 Nov 7 14:30 RunningFast.log.1 -rw-r–r– 1 root root 2.0M Nov 7 12:56 RunningFast.log.2 -rw-r–r– 1 root root 2.0M Nov 7 12:00 RunningFast.log.3 (RunningFast) ➜ staging |
上面的文件之所以没有清空是因为:
别的进程正在使用,正在下载该文件。
【总结】
可以使用:
echo “” > fileName |
去清空文件。
转载请注明:在路上 » 【已解决】Linux中清空某个文件内容