“批量清空日志”的版本间的差异
跳到导航
跳到搜索
(未显示同一用户的4个中间版本) | |||
第1行: | 第1行: | ||
+ | = sudo truncate= | ||
<pre> | <pre> | ||
#!/bin/bash | #!/bin/bash | ||
+ | # 如果sudo | ||
+ | # sudo truncate -s 0 /var/log/nginx/access.log | ||
# 删除 4月的日志 | # 删除 4月的日志 | ||
for loop in `ls | grep hello-wallet_2020-04` | for loop in `ls | grep hello-wallet_2020-04` | ||
第9行: | 第12行: | ||
</pre> | </pre> | ||
+ | =echo= | ||
+ | <pre> | ||
+ | #!/bin/bash | ||
+ | #cd /data/storage/logs | ||
+ | for loop in `ls /data/storage/logs` | ||
+ | do | ||
+ | echo '' >/data/storage/logs/${loop} | ||
+ | |||
+ | done | ||
+ | </pre> | ||
+ | |||
+ | =see also= | ||
+ | |||
+ | [https://blog.csdn.net/qq_31226223/article/details/88869046 truncate Linux下批量备份日志以及清空日志] | ||
+ | |||
+ | [https://www.cnblogs.com/AlexLeeLi/p/10373849.html 使用作业自动批量清理数据库日志文件] | ||
[[category:shell]] | [[category:shell]] |
2022年8月22日 (一) 01:58的最新版本
sudo truncate
#!/bin/bash # 如果sudo # sudo truncate -s 0 /var/log/nginx/access.log # 删除 4月的日志 for loop in `ls | grep hello-wallet_2020-04` do echo > $loop #echo $loop done
echo
#!/bin/bash #cd /data/storage/logs for loop in `ls /data/storage/logs` do echo '' >/data/storage/logs/${loop} done