linux服务器清空文件保留最后20行,命令如下:
cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && tail -n 20 /var/log/nginx/access.log >/var/log/nginx/access_temp.log && mv /var/log/nginx/access_temp.log /var/log/nginx/access.log
[root@logstash nginx]# cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && tail -n 20 /var/log/nginx/access.log >/var/log/nginx/access_temp.log && mv /var/log/nginx/access_temp.log /var/log/nginx/access.log
mv: overwrite ‘/var/log/nginx/access.log’? y
[root@logstash nginx]#
[root@logstash nginx]# cat access.log |wc -l
20
[root@logstash nginx]#
备注:access.log文件被覆盖后,需重启nginx,后续访问nginx应用的日志才会保存至access.log。
使用echo ''>/var/log/nginx/access.log命令清空文件后,无需重启nginx,后续访问nginx应用的日志会持续保存至access.log。
标签:20,log,linux,access,nginx,&&,清空,var From: https://blog.51cto.com/ztj1216/11969526