find \$fpath -type f -mtime +15 -exec rm -rf {} \\; count=\$(cat /tmp/file.out | wc -l) if [ "\$prev_count" -lt "\$count" ] ; then MESSAGE="/tmp/file1.out" TO="[email protected]" echo "Apache Access log files are deleted older than 20 days" >> \$MESSAGE echo ...
/bin/bash# This script will delete all .log files that are older than 30 days.# Directory to search for log fileslog_dir="/var/log/"# Find all .log files that are older than 30 days and delete themfind"$log_dir"-name"*.log"-typef-mtime+30-print0|xargs-0rm...
# chmod +x /opt/script/delete-old-files.sh 最后添加一个 cronjob 自动化此任务。它于每天早上 7 点运行。 # crontab -e 0 7 * * * /bin/bash /opt/script/delete-old-folders.sh 你将看到类似下面的输出。 Apache Access log files are deleted older than 20 days +---+ Oct 11 /var/log/a...
We have a folder named“/var/log/apache/”that contains 15 days of logs and we are going to delete 10 days old files. The articles below are related to this topic, so you may be interested to read. How To Find And Delete Files Older Than “X” Days And “X” Hours In Linux?
find /home -name *.txt Search all text files in /home directory. find . -size 10k -print Find all files greater than 10k in the current directory. egrep "(foo|bar)" file.txt Find the words foo and bar in file.txt. sed s/foo/bar/g file.txt Find the word foo and replace it ...
Similarly, you can list files which areolderthan a certain time by using+instead of-with the number of days. For example, any files older than a year can be listed with: find-mtime+356 Other useful find commands:http://www.mysysad.com/2007/07/using-common-unix-find-command_07.htmlopen...
# chmod +x /opt//delete-old-files.sh 最后添加一个 cronjob 自动化此任务。它于每天早上 7 点运行。 # crontab -e 0 7 * * * /bin/bash /opt//delete-old-folders.sh 你将看到类似下面的输出。 Apache Access log files are deleted older than 20 days +---+ Oct 11 /var/log/apache/2dayg...
# /opt/script/delete-old-files.sh #!/bin/bashprev_count=0fpath=/var/log/apache/2daygeek_access.*find$fpath-typef -mtime+15-exec ls -ltrd {} \; > /tmp/file.outfind$fpath-typef -mtime+15-exec rm -rf {} \;count=$(cat /tmp/file.out | wc -l)if["$prev_count"-lt"$coun...
Search all text files in /home directory. find . -size 10k -print Find all files greater than 10k in the current directory. egrep “(foo|bar)” file.txt Find the words foo and bar in file.txt. sed s/foo/bar/g file.txt Find the word foo and replace it with a bar in file.txt...
$>find/tmp-typef-mtime+30-execrm-rf{}+ While the above commands will delete files older than 30 days, as written, they fork thermcommand each time they find a file. This search can be written more efficiently by usingxargs: $>find/tmp-name'*.tmp'-execprintf'%s\0'{}\;|xargs-0rm...