I have a Solaris System. I am using bash shell.
I want to prepare a script which can do the below.
There are few directories i need to clean.
In those directories, I need to delete files which are older than 3 days. 3 days before files need to be deleted.
The directories are as follows.
CC1,CC2,Int.
The file format inside are(there are many files in the CC1 and CC2 directories)
tmp/test/CC1(dir)-A20140107.2355-0000_jak_file(there are files for every 5 min interval in this format)
A20140107.2355-0000_jak_test(there are files for every 5 min interval in this format)
/tmp/test/CC2(dir)-A20140107.2355-0000_jak_file(there are files for every 5 min interval in this format)
A20140107.2355-0000_jak_test(there are files for every 5 min interval in this format)
It works!
You'll get errors if there are sub-directories. These can be suppressed by -type f or ! -type d .
Further, Unix find offers + instead of \; for -exec ; if the command supports multiple arguments ( rm does) then + is faster.
Then, rm -f suppresses eventual questions when deleting write-protected files.
First, note that putting these three commands on one line with no command separator will NOT do what you want.
Second, you don't need to invoke find three times to do this (unless you run into ARG_MAX limitations).
If the rm utility on your system supports the -v option, try:
(date +"Following files removed at %c:";find /tmp/test/CC[12]* /tmp/file/Int* -type f -mtime +3 -exec rm -fv {} + ) > rm.log
otherwise, try something like:
date + "Following files removed at %c:" > rm.log
find /tmp/test/CC[12]* /tmp/file/Int* -type f -mtime +3 -exec rm -f {} + -exec printf "%s\n" {} + >> rm.log