So I am executing a move script for some files that is older than 1 month every week as follow:

echo "Moving Recordings Older than 30 days!";

/bin/find /var/services/homes/recordings/recording_list/ -type f -mtime +30 \
          -exec mv '{}' /var/services/homes/recordings/Old/recording_list/ \;

I want the script to create a stamped log file and record how many files were found and moved, with a new log file every week, any idea?



To get a log file, add the -v option to mv and collect the output:

find srcdir  -type f -mtime +30 -exec mv -v {} destdir \; >output.log

If you want the log file to contain the date and you have a recent version of bash (>=4.2-alpha), use:

find srcdir  -type f -mtime +30 -exec mv -v {} destdir \; >"$(printf 'file%(%F)T.log' -1)"

If you don't have a recent bash, use date instead.

Faster version

For greater speed, use -exec ... +:

find srcdir  -type f -mtime +30 -exec mv -vt destdir {} + >|"$(printf 'file%(%F)T.log' -1)"

Instead of invoking a new mv process for every file found, this moves many files with a single instance of mv.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.