Lets take an example, wherein we will find and delete file older than 7 days. We will be using the option “-mtime” of the find command for this. 1. Get a list of files using find command as follows: # find /path_to_directory -mtime +7 -type f -exec ls {}\; 2. If...
This article explains how to find all files in a directory that have been changed in the last N minutes or days, or those with a modification date older than N minutes or days, with examples. This is done using the find command. To find the files that have been changed (with the file...
# 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...
给delete-old-files.sh设置可执行权限。 # chmod +x /opt/script/delete-old-files.sh 最后添加一个 自动化此任务。它于每天早上 7 点运行。 # crontab -e 0 7 * * * /bin/bash /opt/script/delete-old-folders.sh 你将看到类似下面的输出。 Apache Access log files are deleted older than 20 day...
This is a very simple tutorial on how to find, move and delete files older than X days. I needed this for a project where I collected some images and needed to archive and delete them after a while.
新建一个可执行文件auto-del-30-days-ago-log.sh,并分配可运行权限 2.2编辑shell脚本: vi auto-del-30-days-ago-log.sh 编辑auto-del-30-days-ago-log.sh文件如下: #!/bin/sh find /opt/soft/log/ -mtime +30 -name "*.log" -exec rm -rf {} \; ...
1. Delete Files Older Than X Hours / Days on Linux With find, you may look for files that have yet to be touched in more than X days and then delete them all. Additionally, you may remove them with a single command if that becomes necessary. ...
# 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...
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="daygeek@gmail.com" echo "Apache Access log files are deleted older than 20 days" >> $MESSAGE ...
tmpreaper is a tool to remove files which are not accessed for a certain period of time. On Linux desktop distros, this is good for cleaning directories like “~/Downloads”, where files get accumulated over a period of time. On Linux server distros, thi