Following command can be used to delete files older than n number of days:
find /usr/local/apache/logs -type f -mtime +15 -exec rm -f {} \;
find - It will search the files in the directory.
/usr/local/apache/logs - destination of the directory.
type f - type is used to search by type of file syatem & f is to find the files only in directory.
-mtime +15 - mtime used to search files according to time & +15 to search files older than 15 days.
-exec rm -f - exec is used to run any command & rm -f to forcefully delete the files.
{} - it will hold the result from the find command and will pass it to exec as input. General syntax -exec <command> {}
\; - '\' will tell the find command to take ; as the end of command else it will also include the ; in find command. '\' is works as "escapes" and tell bash to take ; as new argument.
find /usr/local/apache/logs -type f -mtime +15 -exec rm -f {} \;
find - It will search the files in the directory.
/usr/local/apache/logs - destination of the directory.
type f - type is used to search by type of file syatem & f is to find the files only in directory.
-mtime +15 - mtime used to search files according to time & +15 to search files older than 15 days.
-exec rm -f - exec is used to run any command & rm -f to forcefully delete the files.
{} - it will hold the result from the find command and will pass it to exec as input. General syntax -exec <command> {}
\; - '\' will tell the find command to take ; as the end of command else it will also include the ; in find command. '\' is works as "escapes" and tell bash to take ; as new argument.