Linux - How to find and remove log files directories, Find where does log files present
How to find and remove log files directories
How to locate or find the unwanted log files and remove / clean those log files directoriesFind where does log files are present?
The server's disk spce is consumed lot by log files, storing the unwanted logs is not a good idea for maintaining a server. In the application servers even the admin have have no idea where the application log files are stored. You can use the bellow script to locate the directories where does the log files are stored or where does it located?
Locate the directories where the logs are present
find / -mount -type d -name 'log*' | xargs ls -lSrh | moreThe above command will locate all the directories where does the log files present.
Remove the files older than three days
find ./ -ctime +3 -exec rm {} -Rf \;The above command will remove the files which are older than three days. Note the ./ reperesent the current directory. If you want to remove the files from /var/log directory then traverse to the paricular directory and then remove the files from that directory. Gzip the important files if you dont want to remove it.
find ./ -type f -mtime +3 -exec gzip {} \;This command will locate the files older than three days and will gz or gzip the file. This command is used when you dont want to remove the files but just want to reduce the space of a particular directory or when it it required to gzip the log files. Note: This command will gzip only the files and not the directories. Will gzip the files of present directory.
Find the size of gz files
ls | egrep -v '*.gz' | xargs du -schWhen you have more files the disk usage(du) command will not list all the file size when its huge size, In such situation you can use the above script. Thsi scrip will find only the size of gz files. List and sort files in human readable format.
ls -lSrh
The topic on Linux - How to find and remove log files directories is posted by - Math
Hope you have enjoyed, Linux - How to find and remove log files directoriesThanks for your time