How can I delete files for a particular date ?
I apologize in advance If there is solution please put the link.
Thanks,
How can I delete files for a particular date ?
I apologize in advance If there is solution please put the link.
Thanks,
Does this helps you?
findDate="<YYYYMMDD>"
findPath="<Path>"
find ${findPath} -type f -printf '%CY%Cm%Cd %h/%f\n' | egrep '^'"${findDate}"'' | cut -c10- | xargs -I {} -t rm -f "{}"
Regards!
Thanks! That works. How can I user -exec instead of Xargs ?
As you need for a specific date, you need to filter it with "egrep" and because of it, with this solution, there is no way to do this with -exec.
But if you need for a date range, you can use:
fromMumOfDaysBack=<Days From>
findPath="<Path>"
find ${findPath} -type f -mtime +${fromMumOfDaysBack} -exec rm -f {} \ ;
Before executing, check find manual pages for -mtime option.
Gotcha ! Thanks for your inputs. I really appreciate.
Just one more comment, I am using the %C option of find's -printf argument and it can be changed to %A. Below is what each of them mean:
%Ak - File's last access time in the format specified by k, which is either `@' or a directive for the C `strftime' function.
%Ck - File's last status change time in the format specified by k, which is the same as for %A.
For further information you can check find's man pages (man find) or this link: UNIX man pages : find ()
Regads!