Truncate Clear Linux logs

Large files on /var/log/messages can cause various problems to Linux Operating System and that's why it is advised to rotate your logs on a weekly basis or often if you have a busy server.

To truncate, empty your log files all you need to do is first to locate the large files. Type ls -lah /var/log/ and hit enter. The output should be like:

[root@diver ~]# ls -alh /var/log
total 90M
drwxr-xr-x 14 root root 4.0K Mar 8 04:02 .
drwxr-xr-x 22 root root 4.0K Feb 25 21:22 ..
-rw-r--r-- 1 root root 1.5K Feb 25 21:57 acpid
-rw------- 1 root root 288K Feb 24 12:49 anaconda.log
-rw------- 1 root root 40K Feb 24 12:49 anaconda.syslog
drwxr-x--- 2 root root 4.0K Mar 7 19:55 audit
-rw------- 1 root root 0 Mar 7 04:02 boot.log
-rw------- 1 root root 0 Feb 28 04:02 boot.log.1
-rw------- 1 root root 0 Feb 24 12:51 boot.log.2
-rw------- 1 root utmp 3.3M Mar 8 07:30 btmp
drwxr-xr-x 2 root root 4.0K Nov 11 2007 conman
drwxr-xr-x 2 root root 4.0K Nov 11 2007 conman.old
-rw------- 1 root root 149K Mar 8 10:18 cron
-rw------- 1 root root 828K Mar 7 04:02 cron.1
-rw------- 1 root root 430K Feb 28 04:02 cron.2
drwxr-xr-x 2 lp sys 4.0K Feb 28 04:02 cups
drwx------ 2 diradmin diradmin 4.0K Mar 8 04:22 directadmin
-rw-r--r-- 1 root root 24K Feb 25 21:57 dmesg
drwxr-xr-x 2 mail mail 4.0K Mar 7 04:02 exim
-rw------- 1 root root 17K Mar 3 17:23 faillog
drwxr-xr-x 3 root root 4.0K Mar 8 00:11 httpd
-rw-r--r-- 1 root root 152K Mar 8 10:18 lastlog
-rw-r--r-- 1 root root 113K Mar 8 10:18 lfd.log
-rw-r--r-- 1 root root 70K Mar 7 04:02 lfd.log.1.gz
-rw------- 1 root root 563K Mar 8 10:18 maillog
-rw------- 1 root root 3.7M Mar 7 03:59 maillog.1
-rw------- 1 root root 8.1K Feb 25 21:57 maillog.2
-rw-r--r-- 1 root root 0 Feb 24 13:01 mcelog
-rw------- 1 root root 20M Mar 8 10:18 messages
-rw------- 1 root root 56M Mar 7 04:02 messages.1
-rw------- 1 root root 851K Feb 28 03:59 messages.2

Assume that we want to clear file messages which is 20MB. Just issue the following command:

> messages

and hit enter.  That's all!

Posted on: 08/03/2010








0 Comments
If you want to leave a comment please Login or Register