Not sure where to ask this so here it goes:
I admin an FTP server that has multiple users all rooted under the /data dir. I am creating a script to find all files in /data that are older than 45 days and deleting them. I have this script:
Code:
#! /bin/bash
TODAY=$(date +"%Y%m%d")
# todays date
TIME=$(date +"%R")
# the time now
DIR="/home/USERNAME/45day_delete"
LOGFILE="$DIR/45day_delete-$TODAY.log"
#Where to put the log file
echo "start" - $TIME >> $LOGFILE
find /data -mindepth 3 -mtime +45 -type f -print0 -exec rm {} \; | xargs -0 ls -la >> $LOGFILE
# start looking three levels deeper than /data, ex /data/group/user/
echo "end" - $TIME >> $LOGFILE
currently I have it running minus the "-exec rm {} \;" part so it logs all of the files it would delete. I notice that part of the result set are the .bash* files in the top level of each user's dir. I need to exclude the .bash* files and make sure that this script will react as expected.
I also have a similar file to delete all the ._* files created by Mac systems:
Code:
#! /bin/bash
NOW=$(date +"%Y%m%d")
TIME=$(date +"%R")
DIR="/home/USERNAME/DotUnderscore"
LOGFILE="$DIR/DotUnderscore-$NOW.log"
echo "start" - $TIME >> $LOGFILE
find /data -mindepth 3 -name ._* -type f -print0 -exec cp {} $DIR/copiedfiles/ \; | xargs -0 ls -la >> $LOGFILE
#find /data -mindepth 3 -name ._* -type f -print0 -exec rm {} \; | xargs -0 ls -la >> $LOGFILE
echo "end" - $TIME >> $LOGFILE
I have the script copying the files for now (as a test) and all seems to work fine, nothing but ._* files but... I have seen that there are multiple ways of evoking the find command to delete it's results.
Can someone please explain what the differences are between:
Code:
find / -name * | xargs rm
find / -name * -exec rm {} \;
find / -name * -delete
Please help.