I'm trying to find the files that are older than x days then print their names and the total size to a text file before deleting them, the problem is when I combine more than (-exec) option I got errors. Here is my sh file
#!/bin/bash
cache_location=$1
age=$2
date=`date +%d-%m-%Y`
find $cache_location -mtime $2 -path '*keyword*' -fprint deleted_cache_$date.log -exec du -k {} \; | awk '{total+=$1}END{print "TOTAL SIZE " total/1024/1024 "GB"}' >> deleted_cache_$date.log \;
-exec echo {} | wc -l>> deleted_cache_$date.log \;
-exec rm -r {} \;
Then I call the script like:
.\myscript.sh location +30
The script stops with an error
awk: fatal: cannot open file `;' for reading (No such file or directory)
find: ‘du’ terminated by signal 13
In the log file, I can see all results of find command.