Hello guys I'm writing a script and I need some help. I'm almost done but I think I have a problem with my ffind command. I need the scripts to delete files are 60 days old and then append the filenames to a text file on the days they were deleted. If someone can help me I would be thankful.
One solution:
find . -name "*" -mtime +60 -exec echo {} `date` >> fnames \;
rm `awk '{print $1}' fnames`
Here's an even shorter way. It lists the date once at the top of the section and then lists the files to be deleted:
date >> fnames
find . -name "*" -mtime +60 -print -exec rm {} \; >> fnames
date >> fnames
find . -type f -mtime +60 -exec rm {} \; -print >> fname
if you only want files removed use "-type f" vs name "*"
put the -print after the ";" that way you only log files you CAN remove
Interesting! I think because a semicolon has to come after the -exec option, I assumed that option always had to come last in the "find" command ... but of course the semicolon has a special meaning in this case and doesn't mean it's the end of the "find" command... :o
from the man page.
-exec command
True if the executed command returns a zero value as
exit status. The end of command must be punctuated by
an escaped semicolon. A command argument {} is
replaced by the current path name.