Source From Here
Let's create testing old files:
- 03-1_delete_old_files.sh
Execution outpupt:
- 03-1_delete_old_files.sh
- #!/bin/bash
- # Author: John Lee
- # Date: 2021/07/24
- # Description: This script will delete files older than 90 days
- # Modified: 2021/07/24
- #
- # More:
- # Use below command to create old file for testing
- # touch -d "Thu, 1 March 2018 12:30:00" a
- TARGET_PATH=${TARGET_PATH:-`pwd`}
- for of in `find ${TARGET_PATH} -mtime +90`
- do
- fname=$(basename $of)
- # mv $of "/tmp/${fname}" <--- testing
- rm $of "/tmp/${fname}"
- if [ $? -eq 0 ]; then
- echo "Deleted ${fname} done!"
- else
- echo "Fail to delete ${fname}!"
- fi
- done
沒有留言:
張貼留言