Saturday, September 27, 2008

Kylie A – Sleep

Delete old logs files in Linux

A common task of maintaining Linux operating systems (and that extends to most operating systems based on or clones of Unix) is cleaning the log files. Both the operating system as a database engine few data and proprietary processes can generate large amounts of log files. In the long term, it is necessary to remove these files as we occupy space, have become obsolete and we tend to complicate the search.
 Therefore, based on the original publication "List / Delete files by date in Linux as we can see from the shell to search for and delete old files. Needless to say, that the commands listed below are candidates to be part of a shell script and is likely to be executed by cron. 

Well, enough of words and see some practical examples:
 Find files updated three days ago in the current directory: 

cd / var / log
find-name \\ *. log-mtime +3
 Search 
updated files until three days ago in the current directory and delete them:
find. -Name \\ *. log-mtime +3-exec rm {} \\;

Find the updated files back one day and show its full path:
find / var / log / [az] * \\ *. log-mtime +1
As in the second case, if we delete the files returned by the previous command:
find / var / log / [az] * \\ *. log-mtime +1-exec rm {} \\; addition, we can refine the search more by using the argument-mmin-mtime instead of:

*-mtime n, search for files modified n * 24 hours ago (n days ago) PS: This line can be used to delete old backups if we set a cron to backup a database or other files as tgz. etc.

find *. tgz-mtime +6-exec rm {} \\; (


eliminate having a week old)


source (http://www.luchoedu.org/)






0 comments:

Post a Comment