How to clean log files in Linux
Reference from :https://support.hostway.com/hc/en-us/articles/360001972270-How-to-clean-log-files-in-Linux
hydev@localhost ~]$ du -h /var/log/
du: cannot read directory ‘/var/log/sssd’: Permission denied
0 /var/log/sssd
du: cannot read directory ‘/var/log/samba’: Permission denied
0 /var/log/samba
du: cannot read directory ‘/var/log/ppp’: Permission denied
0 /var/log/ppp
0 /var/log/ntpstats
du: cannot read directory ‘/var/log/audit’: Permission denied
0 /var/log/audit
du: cannot read directory ‘/var/log/mariadb’: Permission denied
0 /var/log/mariadb
0 /var/log/chrony
0 /var/log/glusterfs
172K /var/log/cups
du: cannot read directory ‘/var/log/speech-dispatcher’: Permission denied
0 /var/log/speech-dispatcher
du: cannot read directory ‘/var/log/gdm’: Permission denied
4.0K /var/log/gdm
4.1M /var/log/sa
0 /var/log/qemu-ga
280K /var/log/tuned
940K /var/log/anaconda
0 /var/log/lightdm
24M /var/log/
[hydev@localhost ~]$ sudo du -h /var/log/
0 /var/log/sssd
0 /var/log/samba/old
0 /var/log/samba
0 /var/log/ppp
0 /var/log/ntpstats
38M /var/log/audit
36K /var/log/mariadb
0 /var/log/chrony
0 /var/log/glusterfs
172K /var/log/cups
0 /var/log/speech-dispatcher
684K /var/log/gdm
4.1M /var/log/sa
0 /var/log/qemu-ga
280K /var/log/tuned
940K /var/log/anaconda
0 /var/log/lightdm
61M /var/log/
[hydev@localhost ~]$ sudo cd /var/log/audit
[hydev@localhost ~]$ pwd
/home/hydev
[hydev@localhost ~]$ cd /var/log/audit
bash: cd: /var/log/audit: Permission denied
[hydev@localhost ~]$ sudo cd /var/log/audit
[hydev@localhost ~]$ pwd
/home/hydev
[hydev@localhost ~]$ cd /var/log/audit
bash: cd: /var/log/audit: Permission denied
[hydev@localhost ~]$ chmod -R 777 /var/log/audit
chmod: changing permissions of ‘/var/log/audit’: Operation not permitted
chmod: cannot read directory ‘/var/log/audit’: Permission denied
[hydev@localhost ~]$ sudo chmod -R 777 /var/log/audit
[hydev@localhost ~]$ cd /var/log/audit
[hydev@localhost audit]$ du -h *
5.1M audit.log
8.1M audit.log.1
8.1M audit.log.2
8.1M audit.log.3
8.1M audit.log.4
[hydev@localhost audit]$ du -h
38M .
[hydev@localhost audit]$ cat /dev/null > audit.log.4
[hydev@localhost audit]$ du -h *
5.1M audit.log
8.1M audit.log.1
8.1M audit.log.2
8.1M audit.log.3
0 audit.log.4
[hydev@localhost audit]$ cat /dev/null > audit.log.3
[hydev@localhost audit]$ du -h *
5.1M audit.log
8.1M audit.log.1
8.1M audit.log.2
0 audit.log.3
0 audit.log.4
[hydev@localhost audit]$ cat /dev/null > audit.log.2
[hydev@localhost audit]$ cat /dev/null > audit.log.1
[hydev@localhost audit]$ cat /dev/null > audit.log
[hydev@localhost audit]$ du -h *
0 audit.log
0 audit.log.1
0 audit.log.2
0 audit.log.3
0 audit.log.4
[hydev@localhost audit]$
hydev@localhost audit]$ du -h /var/log/
du: cannot read directory ‘/var/log/sssd’: Permission denied
0 /var/log/sssd
du: cannot read directory ‘/var/log/samba’: Permission denied
0 /var/log/samba
du: cannot read directory ‘/var/log/ppp’: Permission denied
0 /var/log/ppp
0 /var/log/ntpstats
8.0K /var/log/audit
du: cannot read directory ‘/var/log/mariadb’: Permission denied
0 /var/log/mariadb
0 /var/log/chrony
0 /var/log/glusterfs
172K /var/log/cups
du: cannot read directory ‘/var/log/speech-dispatcher’: Permission denied
0 /var/log/speech-dispatcher
du: cannot read directory ‘/var/log/gdm’: Permission denied
4.0K /var/log/gdm
3.9M /var/log/sa
0 /var/log/qemu-ga
280K /var/log/tuned
940K /var/log/anaconda
0 /var/log/lightdm
23M /var/log/
[hydev@localhost audit]$ sudo du -h /var/log/
0 /var/log/sssd
0 /var/log/samba/old
0 /var/log/samba
0 /var/log/ppp
0 /var/log/ntpstats
8.0K /var/log/audit
36K /var/log/mariadb
0 /var/log/chrony
0 /var/log/glusterfs
172K /var/log/cups
0 /var/log/speech-dispatcher
684K /var/log/gdm
3.9M /var/log/sa
0 /var/log/qemu-ga
280K /var/log/tuned
940K /var/log/anaconda
0 /var/log/lightdm
24M /var/log/
[hydev@localhost audit]$ sudo chmod -R 777 /var/log/sa
[hydev@localhost audit]$ du -h *
12K audit.log
0 audit.log.1
0 audit.log.2
0 audit.log.3
0 audit.log.4
[hydev@localhost audit]$ cd /var/log/sa
[hydev@localhost sa]$ du -h *
112K sa02
176K sa03
216K sa04
168K sa05
180K sa06
168K sa09
196K sa10
260K sa11
4.0K sa12
184K sa14
132K sa15
100K sa16
180K sa20
120K sa21
208K sa22
188K sa23
216K sa26
196K sa27
192K sa28
152K sa29
20K sa30
140K sar03
216K sar11
176K sar26
[hydev@localhost sa]$ pwd
/var/log/sa
[hydev@localhost sa]$ sudo chmod -R 777 /var/log/cups
[hydev@localhost sa]$ cd /var/log/cups
[hydev@localhost cups]$ du -h *
0 access_log
80K access_log-20170314
56K access_log-20170322
8.0K access_log-20191123
4.0K access_log-20191203
0 error_log
4.0K error_log-20170314
4.0K error_log-20170322
4.0K error_log-20191123
4.0K error_log-20210721
0 page_log
4.0K page_log-20191123
[hydev@localhost cups]$ cat /dev/null > access_log-20170314
[hydev@localhost cups]$ du -h *
0 access_log
0 access_log-20170314
56K access_log-20170322
8.0K access_log-20191123
4.0K access_log-20191203
0 error_log
4.0K error_log-20170314
4.0K error_log-20170322
4.0K error_log-20191123
4.0K error_log-20210721
0 page_log
4.0K page_log-20191123
[hydev@localhost cups]$ cat /dev/null > access_log-20170322
[hydev@localhost cups]$ cat /dev/null > access_log-20191123
[hydev@localhost cups]$ cat /dev/null > access_log-20191203
[hydev@localhost cups]$ cat /dev/null > error_log-20170314
[hydev@localhost cups]$ cat /dev/null > error_log-20170322
[hydev@localhost cups]$ cat /dev/null > error_log-20191123
[hydev@localhost cups]$ cat /dev/null > error_log-20210721
[hydev@localhost cups]$ cat /dev/null > page_log-20191123
[hydev@localhost cups]$ du -h *
0 access_log
0 access_log-20170314
0 access_log-20170322
0 access_log-20191123
0 access_log-20191203
0 error_log
0 error_log-20170314
0 error_log-20170322
0 error_log-20191123
0 error_log-20210721
0 page_log
0 page_log-20191123
[hydev@localhost cups]$
Comments
Post a Comment