$7.49 .com domain with free InstantPage Website Builder$1.99 Web Hosting   捷飞网络官方淘宝店   Godaddy 优惠码
返回列表 发帖
分享到:




[应用&技术] 分享下在Linux vps 下如何清除系统日志

Linux的文件系统比Windows的要优秀,不会产生碎片,对于长时间运行的服务器来说尤为重要,而且Linux系统本身也不会像Windows一样产生大量的垃圾文件。不知道这个说法有没有可信度!至少我们可以确定的是linux系统的文件系统是比较优秀的!/ X3 i& _- p# y
把一下代码保存为.sh后缀脚本来运行即可清除Linux系统日志#!/bin/sh / @1 o3 a2 r2 q5 d  @! [  d
cat /dev/null > /var/log/syslog
, q* D, P0 k: H3 I9 w( N, L( @cat /dev/null > /var/adm/sylog
; R* H0 o9 D3 O' T2 tcat /dev/null > /var/log/wtmp
/ W) u. g, A9 D2 S; M: l" x# h6 ^cat /dev/null > /var/log/maillog # u5 m. H. p/ Q+ I( Y% L
cat /dev/null > /var/log/messages & j/ p7 p! ]7 s! l9 G" q
cat /dev/null > /var/log/openwebmail.log 7 q: f8 ]# e9 k# `
cat /dev/null > /var/log/maillog * W* O2 m( s% v2 g
cat /dev/null > /var/log/secure
$ s' V8 Q2 W* w6 r1 Bcat /dev/null > /var/log/httpd/error_log
, g" Q% Y) @; k9 ^" T$ a* Z# Hcat /dev/null > /var/log/httpd/ssl_error_log ) |" A9 K! f6 f; H7 I5 G* F2 s
cat /dev/null > /var/log/httpd/ssl_request_log
7 a& i% Q7 y! X% k) y6 acat /dev/null > /var/log/httpd/ssl_access_log & i& o* z1 l* }0 P1 R& ^, ~( C

( Z" E& c1 l2 A( |! J/ p# o另外清理linux系统垃圾还有以下命令sudo apt-get autoclean 清理旧版本的软件缓存
& C( k& g* l4 H8 ]; M8 ^3 b5 z# f) Osudo apt-get clean 清理所有软件缓存4 V% l$ Z: n( c' n, ^; V& Q
sudo apt-get autoremove 删除系统不再使用的孤立软件

本帖最后由 jim9 于 2012-8-8 15:35 编辑 8 W, L: x, u+ H9 s6 l& e' M

4 Q# @! x/ F3 Y2 c# T# U1 u, e$ ?使用过Windows的人都知道,在使用windows系统的过程中系统会变得越来越慢。而对于Windows下饱受诟病的各种垃圾文件都需要自己想办法删除,不然系统将会变得越来越大,越来越迟钝!windows怎么清理垃圾相信大家都知道的,那么linux下怎么清理系统垃圾呢?
/ L! ?+ F( h  m. ELinux的文件系统比Windows的要优秀,不会产生碎片,对于长时间运行的服务器来说尤为重要,而且Linux系统本身也不会像Windows一样产生大量的垃圾文件。不知道这个说法有没有可信度!至少我们可以确定的是linux系统的文件系统是比较优秀的!! l9 J' K, s! N) O
$ z- Q' Q; N6 v, X0 T
  W4 `* \) e' W& ^
错误, |6 ^1 L7 t2 o# p- ^6 j4 ?
; u# m! ?$ e6 \: u  k1 Q9 @rm -f logfile3 z) M6 W: R+ g% i; t4 g

0 W, ?7 |& C7 Z6 n, g, \3 Q- E/ L原因
5 s) b8 F( ?8 O- t5 R应用已经打开文件句柄,直接删除会造成:
$ y* V/ v! O) i2 ~- m应用无法正确释放日志文件和写入' ~8 h4 ]4 a$ I7 l- `( p% D. {
显示磁盘空间未释放
6 K2 A9 p% |/ ]4 Q# `正确7 u4 N8 [% t6 Y& M" _- `) B+ I1 s7 P9 Z+ l
8 n% a6 Z& A5 U( |: u
  1. cat /dev/null > logfile
复制代码
; u& d( V7 C0 N! ^( F/ W9 f
' y) T  F4 u1 m) U$ n8 j2 I
把一下代码保存为.sh后缀脚本来运行即可清除Linux系统日志
' c% z+ `6 h* \
  1. #!/bin/sh
  2. cat /dev/null > /var/log/syslog
  3. cat /dev/null > /var/adm/sylog
  4. cat /dev/null > /var/log/wtmp
  5. cat /dev/null > /var/log/maillog
  6. cat /dev/null > /var/log/messages
  7. cat /dev/null > /var/log/openwebmail.log
  8. cat /dev/null > /var/log/maillog
  9. cat /dev/null > /var/log/secure
  10. cat /dev/null > /var/log/httpd/error_log
  11. cat /dev/null > /var/log/httpd/ssl_error_log
  12. cat /dev/null > /var/log/httpd/ssl_request_log
  13. cat /dev/null > /var/log/httpd/ssl_access_log
  14. cat /dev/null > /var/log/brcm-iscsi.log
  15. cat /dev/null > /var/log/btmp.1
复制代码
# C  j1 w; z+ e: L1 n, u5 b
% b8 _+ j' D. ~+ [1 c2 F7 y) |
5 ?% W) ^9 ?7 J  r, P
另外清理linux系统垃圾还有以下命令" d8 Y5 _9 r2 d% m6 N# X/ M8 }$ J$ X' Y" L& E* _; m) T
sudo apt-get autoclean 清理旧版本的软件缓存( R2 i  B4 ]% ?
9 M  p/ v8 M. [2 K4 h4 psudo apt-get clean 清理所有软件缓存9 X; P! S% m8 ~+ G+ L# f8 ?
sudo apt-get autoremove 删除系统不再使用的孤立软件
* G/ g+ r8 k6 F" t; _7 K, }
/ w3 D; L" F% D+ d) U8 @4 x$ r. }4 N2 V% e8 G( D* Q9 l# V
总结:$ T- m' B0 x1 ]
; n. p8 W, y) M: p  I& J0 U* \; |1 b9 V
) K/ h) o( y) c1 }6 n希望本文介绍的Linux下清除系统日志方法能够对读者有所帮助,更多有关linux系统的知识还有待于读者去探索和学习。




TOP

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全