James, all, As you've seen, there are multiple interpretations of what you requested. Fortunately, the find command can support all of those. If what you really wanted is what you said, files _created_ more than 5 days ago, the -ctime predicate is (as close as you're going to get to) what you want. As Alan points out, that field is really when the inode was last changed for whatever reason.
If you want to only remove files that are older than 5 days, and haven't been modified in that time, the -mtime predicate will do that. If you want files that are older than 5 days, and haven't been accessed in that time, the -atime predicate does that. If you look at the man page for find, it will tell you how to specify the values for the times: Numeric arguments can be specified as +n for greater than n, -n for less than n, n for exactly n. If you just use -?time 5, and the command is only run once, it will only delete files that were (whatever) 5 days ago, no more, no less. So, any files that are 6 days old and up will be left untouched. So, what you want is +5 (or +4 depending on your needs). The other thing to note is the "-type f" clause Neale specified. If you don't use that, then the find command will also report directories, links, sockets, etc. If you combine that with an "rm -rf" command, large portions of a file system could go away that you don't want to go away. Finally, there is a subtle difference between doing an -exec rm and piping the output of find to an xargs rm command. The difference there is that the find command will invoke the rm command once for each file that it finds that matches your criteria. The xargs version will "batch" them up to the maximum line length that is allowed on your system, and invoke rm once for each maximum number of arguments, thus reducing the amount of system overhead required for process creation and destruction, etc. I tend to use that a lot these days. It really does speed things up when there are a lot of objects to be handled. Mark Post -----Original Message----- From: Linux on 390 Port [mailto:[EMAIL PROTECTED] On Behalf Of James Melin Sent: Thursday, July 22, 2004 10:53 AM To: [EMAIL PROTECTED] Subject: Deleting files in a directory more than 5 days old I am wondering what string of commands are necessary to delete all files in a directory that were created more than 5 days previously. I know it's gonna be a compound command and/or script but I'm not sure what exectly to code. Anyone have anything in their bag of tricks I could adapt? ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
